Commit Graph

185 Commits

Author SHA1 Message Date
Vsevolod Fedorov eb08e60765 Story 2011049: Delete also old views when --delete-old option is specified
Improve 'update' command to handle old views also, not just jobs.

Task: 49601

Change-Id: I60431f662d5a69c084b2698d08104a1524d02767
2024-03-25 12:47:40 +03:00
Thanh Ha 5a98ebb8bb
Fix flake8 BLK100 and BLK999 issues
Resolves flake8 BLK related issues.

"BLK100 Black would make changes."
"BLK999 Unexpected exception: ..."

Change-Id: Ic6d4265e3d02b2f2a15ab851eaed98288c62730c
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
2020-08-31 10:54:19 -04:00
Thanh Ha 67dc0087a7
Switch to debug log level for not deleting job
The spam caused by jjb not doing anything with a job is not
generally interesting so switch it to a DEBUG level logger.

Change-Id: I0c5277612c8db3a11a1e44d4855b4a51226a8f2c
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
2019-11-22 10:07:06 -05:00
Thanh Ha 4d90c187a9 Auto-generated output from python-black
Please review the following patch containing the code changes in
the repo. This patch is a transition patch and is the auto-generated
output of the python-black tool.

Change-Id: I2d2de71da8a105fb62b561899ae78441ddab4032
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
2019-09-09 19:23:24 +01:00
Achim Leitner cbc6819978 Fix encoding error in builder.py
When calling `jenkins-jobs update --delete`, the builder will create an
XML dom tree from the xml string. It fails to correctly encode the
string, which results in a UnicodeEncodeError if the string contains any
non-ascii characters.

Story: 2006374
Task: 36163
Change-Id: I2caf91dcaf2c1b6c03e92a485a3aa51b038b40b1
Signed-off-by: Achim Leitner <git@fjl.de>
2019-08-08 10:22:45 +02:00
Thanh Ha e07ad13ad0
Print config-xml warning once
Instead of printing the deprecation warning against every generated
config-xml file, print it only once at the beginning of the test
command call to not spam the console.

Change-Id: Ifdcdb1373d44ba6232ea7a5359662cc760353774
Signed-off-by: Thanh Ha <zxiiro@linux.com>
2018-11-15 16:28:40 +08:00
Sorin Sbarnea 144ace119b
Improve unicode support
Printed job urls with unicode are now clickable

Avoids unicode decode errors in logging due on
systems, likely python27 systems where
default encoding is ascii.

Change-Id: I17041de05a4388c7b95a9ca04477043424458c67
2018-06-17 15:53:02 +01:00
Alphadose 43eb89fc54 Deprecate running testjobs without config-xml flag
Creation of nested folders is not possible in
`project-type: folder` in test mode because the
folder name conflicts with the generated XML
filename and an `OSError` is thrown as a result.
This can be resolved by passing the `--config-xml`
flag when running the jobs in test mode. This
commit displays a deprecation message asking the
user to use the `--config-xml` flag.

Change-Id: I6f883040ed3d9b3536ccc2fb305cdddcfde5d765
Story: #2001937
Task: #15050
2018-05-20 12:57:29 +00:00
Zuul 60602ea938 Merge "Add 'existing-only' argument for update subcommand" 2018-04-12 19:59:13 +00:00
Zuul d0b438cf25 Merge "Delete old managed folders when calling update subcommand with --delete-old option" 2018-04-12 19:08:55 +00:00
Sorin Sbarnea cd90a7e2a5
Include view url in logs when possible
Makes view logging similar to job one so URLs are printed
inside the logs.

Also assured that URLs for both, views and jobs, are
ending with slash as thats the what Jenkins expected format.

Change-Id: Id34a25b47b4f584f07cc2dc2039cc1a49ab49038
2018-04-06 10:01:09 -04:00
Ayoub Elhamdani e0f19f39cd Delete old managed folders when calling update subcommand with --delete-old option
This should be merged first https://review.openstack.org/#/c/519340/

Change-Id: I8ed1540b024bfcfaad1221d4e4a0da4a56b56c3c
Task: 5834
Story: 2001286
2018-04-05 11:36:36 +00:00
Malcolm Brooks fc1f6fde54 Add 'existing-only' argument for update subcommand
Additional argument for the update subcommand to allow user to update
only jobs currently installed on the Jenkins server and managed by
this tool.

Change-Id: I4b0e997df01057f89896b8caa27dc00b5ca077df
2018-04-04 19:01:50 +01:00
Sorin Sbarnea 713b660aaf Moved create directory log level to debug
Avoids console span when running in non verbose mode,
especially when using --config-xml which would
create one folder for each job created.

Change-Id: Id5d47c50c5c364068c26437c125e4066b856587c
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2018-03-14 10:55:30 +00:00
Zuul 96aa1c756f Merge "re-raise the original Exception instead of raising a new one" 2018-02-23 16:36:23 +00:00
Sorin Sbarnea b76ed1629d Added option to print job names as urls
Add print_job_urls = True to [job_builder] to enable output as urls
instead of simple job names when changing them.

Change-Id: I3454606a50ca385c87d8c13d3eab5d30d94cf02f
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2018-01-26 14:14:07 +00:00
Evgeni Golov f2c4453df3 re-raise the original Exception instead of raising a new one
this preserves the error traceback and makes debugging easier

Change-Id: Ia513ac009b81d35e3df11939771aa29e40700c08
2017-11-06 13:36:17 +01:00
Darragh Bailey af9d984baa
Basic folder support
Allows specifying a folder attribute for each job generated, which in
turn is used when creating or uploading to place the job under the
requested folder.

The job name is expanded after defaults are applied, to support the
attribute being defined within a set of defaults applied to a number of
jobs.

This in turn allows for multiple jobs with the same basename to exist,
provided they are targeted at different folders.

Does not support creating the folders if they do not exist.

Change-Id: I8c2157c4c81087cc972a048d1b88d5f08ac65361
2017-10-23 13:29:21 -04:00
Sorin Sbarnea 6a9d5736d6 use alphanum sorting for jobs and views
This improves UX by using a alphanum sorting which
is more natural to humans: [a1, a2, a10] instead of
[a1, a10, a2].

Change-Id: Ice9c3de282f08e85c8f8a34a27d1b6c0502ca9cb
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2017-08-09 17:51:00 +01:00
Daniel Watkins cc200dade0 Use default plugin list when listing Forbidden
Listing the plugins installed on a Jenkins instance requires full
administrative permissions.  For cases where we don't have permission to
read the plugin list, we should just fall back to the default list.

Story: 2000618
Task: 3052

Change-Id: I924f237f5f175216200668d133092f2357f6d9d3
2017-07-31 09:53:12 -04:00
Peter Eisentraut 919052714c Add option to make test output file layout match Jenkins
Before, `jenkins-job-builder test -o outdir` would write

    outdir/job_name

With the new option `--config-xml`, it writes

    outdir/job_name/config.xml

to match the layout that Jenkins uses internally.  This is more useful
for diffing against existing Jenkins installations or uploading job
definitions by other means.

Also, it seems better to give the output files an .xml extension.

Change-Id: I78fc7aff531925ee071b8e19f40f766b4af0b5ad
2017-05-27 12:22:06 +01:00
Sorin Sbarnea 8a7d77c180 Removed some deprecation warnings and enabled py35 on tox.
Change-Id: Icc5b28c4636b542a10502b7b1d2d2dc2028cc166
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2017-03-12 19:43:33 +00:00
Darragh Bailey bfb18520e6 Ensure keep is an iterable
If no value is provided for 'keep' when calling delete_old_managed,
ensure a default empty iterable is used to prevent an exception.

Change-Id: I3110f8e03e287a6ff067b992ed8631e34121a8d2
2016-11-14 13:40:03 +00:00
Thanh Ha 1deb3aff4c
Add view management functionality
- Adds the ability for JJB to work with views
- Views can be created, updated, and deleted.
- New modules for List view and Build Pipeline view are added
- New tests for testing the deletion of views

Example View configuration:

    - view:
        name: MyView
        view-type: list

Change-Id: Idb29a4407bcc14593e10a4d951036cb04e8e6c27
Co-Authored-By: Brandon Leonard <brandon.leonard@rackspace.com>
Co-Authored-By: Joao Vale <jpvale@gmail.com>
Co-Authored-By: Lucas Dutra Nunes <ldnunes@ossystems.com.br>
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
2016-10-14 09:14:21 -04:00
Wayne Warren e9a295b1fb Move CacheStorage to its own module.
And rename it to JobCache. The word "Cache" already implies "Storage"
so it makes more sense to name it after the things that it
stores...Jobs!

Change-Id: If7a7a56e8f6a3637f62e285eaa7ba989f67002dc
2016-09-02 08:58:09 -07:00
Wayne Warren e75062d103 Merge builder.Builder and builder.Jenkins
Since both of these classes essentially build on basic functionality
provided by jenkins.Jenkins, merge them into a single class. Name this
class "JenkinsManager" to avoid confusion with jenkins.Jenkins.

Also moves some tests for update timeout configuration into the
tests.cmd.test_config module from tests.cmd.subcommand.test_update
module, replacing those tests with skipped stubs as reminders to
figure out a better way later.

Change-Id: I13c17bc90e29e702e5e02992e93cf3cdc689731d
2016-09-02 08:58:09 -07:00
Wayne Warren 2236a00c53 Rename Builder.delete_job to Builder.delete_jobs.
Change-Id: If57a98a00e9577fdf7a3d7585905a2102d8c61cd
2016-08-20 11:28:00 -07:00
Wayne Warren 1fe7709923 Remove unused builder.Builder.update_job method
The deprecation warning message in this method was confusing and
seemed to be intended for builder.Jenkins.update_job but it's hard to
tell for sure. Seems likely to be an artifact of an outdated patchset
in the parallelize-the-things work done last year because it's not
clear how it could apply to builder.Builder.update_jobs which has a
significantly different use case than parallel_update_job.

Change-Id: Ifb3c1a40d81b0d43ac8e85151f0a99d1502e21db
2016-08-20 00:46:57 -07:00
Wayne Warren 8ffb11a4bf Be explicit about objects exported by modules.
Change-Id: Iaea087c6c3a024922034423a8d56571184f33b7c
2016-08-20 00:34:35 -07:00
Wayne Warren c80e3bc5e9
Cleanup various deprecation warnings.
Change-Id: Iec16a5965d62bebb50d3e7307ab93c59304a9ab6
2016-08-20 01:24:49 -04:00
Wayne Warren dfc0efb79c
Rename "parallelize" decorator to "concurrent"
It came to my attention when I was deciding whether or not to use the
jenkins_jobs.parallel.parallelize decorator to parallelize things in
jenkins_jobs.parser that because it is using the Python threading
library nothing is actually parallelized, only concurrentized (at least
for CPython).

I actually think concurrency is fine for the original use case since
that (ie, updating Jenkins jobs) is primarily I/O bound on network
connections to a Jenkins instance. However, the "parallel" name really
is misleading and could actually be harmful for users of this API who
may mistakenly have the impression that it can be used to speed up
CPU-bound tasks.

Also removes seemingly unnecessary usages of this decorator. ie,
jenkins_jobs.builder.Jenkins.changed that is never actually calle
with a list of arguments.

Change-Id: I996f9dea440e2d6b67ea70870d22942d6eef3ec7
2016-08-18 22:47:48 -04:00
Wayne Warren 7373201882 Move 'delete' yaml parsing to JenkinsJobs.execute.
This is the final piece of YamlParser in jenkins_jobs.builder, so also
remove the imports and make trivial fixes to test methods to prevent
borked test cases.

Change-Id: Ida543fa14c70447ae506092ec8afd5cb6caaa629
2016-08-05 08:32:46 -07:00
Wayne Warren 3ce6618381 Move 'update' yaml parsing to JenkinsJobs.execute.
1 Remove YamlParser from Builder.
 2 ...
 3 Rule the world.

Change-Id: Id465078da2a7016fd59407516fe124602abd016c
2016-08-05 06:40:12 -07:00
Wayne Warren c569dc02d3 Move load_files method to YamlParser from Builder.
This is the first step in removing jenkins_modules.parser.YamlParser
references from jenkins_jobs.builder.Builder entirely, necessary
because load_files is actually a YamlParser behavior, not a Builder
behavior.

Change-Id: I1cad99b4cdb44af25ba398837f7f328cfcbd5bbb
2016-07-22 17:33:53 +01:00
Wayne Warren 4f04de1f9a Use JJBConfig in YamlParser.
This commit sees JJBConfig start to take the form it ought to have,
namely using attributes to represent different logical sections of
configuration that target specific subsystems of JJB.

It also moves ConfigParser data retrieval from
jenkins_jobs.modules.helpers.get_value_from_yaml_or_config_file() to
jenkins_jobs.config.JJBConfig.get_module_config()

TODO: Add JJBConfig tests to validate the behavior of JJBConfig in
specific circumstances.

Change-Id: I053d165559f5325a2f40b239117a86e6d0f3ef37
2016-07-22 17:33:25 +01:00
Sebastian Schuberth df1ab0f01a Catch OSError when renaming and try to remove the destination file first
Otherwise the rename fails on Windows if the destination file already
exists.

Change-Id: Id15cfaa5b9278d7e932a7975ab6e5a878b31a642
2016-06-09 11:49:30 +02:00
Darragh Bailey 7d13236760 Python 3.x tempfile requires unicode
Explicitly encode the output of yaml dump, and allow tempfile to handle
the unicode output as it works correctly for python 2.7 and 3.x+

Change-Id: I919b2565a7f3857586ee6cc09b787160472e9deb
2016-05-25 19:15:22 +01:00
Darragh Bailey 85ee46297c Prevent corruption of cache by using atomic update
Ensure that cache is written to a temporary file and use an atomic OS
file rename operation to ensure that the cache is either the old
contents or new contents and cannot be corrupted by an exception
occurring during writing or should the process be killed.

Change-Id: I69947cc6d80fdc80ee7addde3a2ff87cd9c3297b
2016-05-20 14:43:25 -07:00
Jenkins a725ca89af Merge "Wrap stdout object only once with wrap_stream" 2016-04-21 23:15:11 +00:00
Clark Boylan 5407302fdc Revert "Allow using lockfile per jenkins master"
This reverts commit d1df3359b3.

The lockfile management code attempts to do IO on a closed file and
throws errors.

Change-Id: Ied58185758fd7c8c822624e169216441341a75d0
2016-03-16 10:26:18 -07:00
Jenkins 0c8ce8ce8f Merge "Allow using lockfile per jenkins master" 2016-03-16 00:11:17 +00:00
Yolanda Robla d1df3359b3 Allow using lockfile per jenkins master
When a jjb run is thrown when another jjb is already running,
it can cause corruption of cache. Start using a lockfile to
ensure this won't be happening and run securely on automated
systems.

Change-Id: I3ac37e738b3bb87c04a47afb8adb3e25f8fb4ea8
2016-03-14 17:28:39 +01:00
Joakim Löfgren aa3bf5cc19 Fix issue with non-ascii characters in get_job_md5
The xml string needs to be encoded to utf-8
before passing it to the hash function.

Change-Id: I4b6ca7ef459b48a2ba56f788fe37307ee381ced4
Story: 2000488
2016-02-23 09:10:25 +01:00
Thanh Ha bd1c93199a
Fix delete-all command to include all job types
getProjects() only includes simple job types like Freestyle jobs but
ignores more complex job types like Maven and Matrix jobs. This API is
also marked as deprecated in Jenkins so we probably shouldn't be using
it anyway.

Instead switch to using getAllItems() which pulls down all job types. It
is also possible to pass a parameter such as AbstractProjects or more
specific to specify exactly which job types we want to remove. In this
case though we want all of them so no need to pass any parameters.

See:
http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html

Change-Id: Ia4e37bc1d4bde70cf8f83783edd6b861eed6c2e3
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
2016-02-03 19:25:47 -05:00
Darragh Bailey e1f5dec356 Wrap stdout object only once with wrap_stream
Make sure to perform wrap external to loop, as otherwise this will
recursively wrap the output object and potentially result in getattr
lookups exceeding the recursion limit in python.

Change-Id: Ie9318a3d23a721e62c16e7b05f52d5b9bec1bb82
2016-01-11 18:35:20 +00:00
Jenkins 71449dbed9 Merge "Distinguish kept jobs and unmanaged jobs when skipping removal" 2016-01-11 16:48:24 +00:00
Darragh Bailey 8805a34c0f Reorder imports to match hacking guidelines
Ensure that the imports follow the standard OpenStack hacking
guidelines.

Change-Id: Iaa4326aef118ddfd807dd006934f1d9ca80a1cfa
2015-12-23 15:23:42 -08:00
David Caro 333fdc65a1
Add parallelization options
* Only update_jobs uses the parallel features right now
* --workers N
    - If set to 0, it will use parallel execution and
      use the number of cores in the machine as thread count
    - Any other value enables the parallel extensions and sets the
      number of concurrent threads to that value
    - Will use 1 by default

Add some tests to make sure the parallel execution helpers work as
expected.

Change-Id: Ib0abd34ea7525f75fff4ff480287a6e589deba90
Signed-off-by: David Caro <dcaroest@redhat.com>
2015-12-01 10:05:04 -05:00
Jenkins 511c3ad577 Merge "builder.py: fix potential race condition" 2015-11-14 06:46:06 +00:00
Khai Do 899bc6c946 fix for python 3, decode job output
Change Ie952617a34c0719e forced utf-8 format but forgot to decode the
xml when passing to update_job. This broke jjb for python 3:

 File "/Users/khaido/PycharmProjects/jenkins-job-builder
     /jenkins_jobs/builder.py", line
 134, in update_job
    self.jenkins.create_job(job_name, xml)

 File "/Users/khaido/PycharmProjects/jenkins-job-builder/.tox
      /py34/lib/python3.4/site-packages/jenkins/__init__.py",
 line 852, in create_job
      config_xml.encode('utf-8'), DEFAULT_HEADERS))
  AttributeError: 'function' object has no attribute 'encode'

Change-Id: Iceda46214bf4709ccd8141ef654cf3ec81e8af06
2015-10-13 00:26:20 -07:00