Commit Graph

156 Commits

Author SHA1 Message Date
Vsevolod Fedorov 6b92807cd7 Tests: Rename yamlparser tests and fixture directories
Rename fixtures directory to job_fixtures to prepare for adding view_fixtures
directory in the following commits.

Change-Id: Ic20997cae020b542ddc22bf444fa6b92fbcae064
2023-01-26 11:06:23 +03:00
Vsevolod Fedorov 0e1b708ad5 Yaml parser tests: Add test for job parameters precedence
Change-Id: I6ebc93425b44a7981b3befc931486e0a7a5d253b
2022-12-20 10:44:43 +03:00
Eren Atas 08678825a9 Update Gerrit Trigger Plugin Implementation
The changes between plugin version 2.30.0-2.32.0 have been
implemented. Current test cases are updated, and also new
test cases are added in order to verify old version XML
output has not been altered.

Documentation uses gerrit004.yaml as an exampple, therefore,
`build-cancellation-policy` have also been implemented to
show as example.

Signed-off-by: Eren Atas <eatas.contractor@libertyglobal.com>
Change-Id: I55fb6f8dd722d50cff369a6fba0e11c96b0c08aa
2021-05-20 15:14:46 +02:00
Ruslan Marinin 15a0896791 fixed broken active choice reactive param after job creation
Change-Id: I7e7362a73e9478bdbd445f5178f982afa346f58a
2021-04-29 20:24:20 +03:00
Zuul 57cd9e7dc2 Merge "Added support of Active Choice Reactive Parameter" 2021-04-10 14:00:37 +00:00
Igor Lakhtenkov f810d8bc30 Added support of Active Choice Reactive Parameter
Change-Id: I25e926603682db543658aad82efb6eb41d1b5cb4
Task: #42221
2021-04-07 01:33:01 +03:00
sp-ricard-valverde c1d8a41666 feat(scm): add git extension for lfs-pull
Add a missing extension to git scm which enables the option to do
"Git LFS pull after checkout"

Add lfs-pull fixtures

Change-Id: Ie8b98877f3f282ac0b32dbeb089e6d0d9ccc25c8
2021-03-16 18:29:56 +01:00
Zuul 4f615ee5ec Merge "Fix 'authorization' property one more time" 2021-02-15 19:53:03 +00:00
Adam Romanek c0866c56b9 Fix 'authorization' property one more time
Due to the fact how dispatching works the 'authorization' property
handler was not always invoked through Properties.gen_xml(), leading to
a bug and an invalid test case: project-with-auth-properties.(yaml/xml)

This change pushes the logic for determining if the object is a
folder/multi-branch project from Properties.gen_xml() to the
authorization() function itself. For that to work the authorization()
function needed access to the top-level job object, which is now
conditionally passed to each dispatched function as a keyword argument,
if the function takes 'job_data' argument. Note that taking this
argument is completely optional so no changes were required in other
handlers. In the future the same approach could be taken to eliminate
the hacks for 'uno-choice' in Parameters.gen_xml().

Additionally ModuleRegistry.dispatch() now merges the top-level job
object with any template data before deep-formatting, so that job-level
properties are now available in Jinja templates. A very nice use case
is in project-with-auth-j2-yaml.yaml test case.

Change-Id: I9a49de74055cd9acfdc87dbad1fc454548643e8f
2021-02-02 16:20:52 +01:00
Adam Romanek c4e2f03776 Fix support for !j2-yaml tag on project level (missing deepcopy impl)
The properties of 'project' objects are deepcopied in
YamlParser._expandYamlForTemplateJob(), including any Jinja2YamlLoader
objects produced by !j2-yaml tag. Because of the missing __deepcopy__()
definition in Jinja2YamlLoader, the parent class' implementation was
used, causing the deepcopied object be of Jinja2Loader type.
Consequently the rendered value was always a string, not an instance of
LateYamlLoader as it supposed to be.

This change fixes the issue in Jinja2YamlLoader and potentially in
LateYamlLoader, however the latter is currently not deepcopied anywhere
so no test could be written to cover it.

Change-Id: I24fda368a4af0e9aac7b78c478ac7b4eddf27b9b
2021-02-01 23:35:39 +01:00
Eren ATAS 6cad52986e Active Choices parameters support
Following parameters have been implemented in JJB:
- Active Choices Parameter
- Active Choices Reactive Reference Parameter

Test cases also have been written.

Change-Id: I6e953aa26114fde9ff293ed17cc17d5972df9af3
Signed-off-by: Eren ATAS <eatas.contractor@libertyglobal.com>
2020-10-12 14:00:54 +02:00
Zuul cf8b2721ed Merge "Introduce a new '!j2-yaml:' tag" 2020-09-25 15:25:31 +00:00
Adam Romanek 6bc5398336 Introduce a new '!j2-yaml:' tag
The tag provides Jinja templating capabilities for generating parts of
YAML structures. Two potential use cases are provided as test cases and
are linked in the documentation.

The new tag should also help address some use cases people were asking
about, like here:
https://groups.google.com/g/jenkins-job-builder/c/HkVZVuBDlKM.

Change-Id: I96392e42c3c79a9be0a8f736506908701251dd62
2020-09-14 14:37:31 +02:00
Eren ATAS a24a547de0 Updated ext-email support
Added also a test case for version specific changes

Change-Id: I5213dccffc441037c63ee7c042aee4a8a84d9732
Signed-off-by: Eren ATAS <eatas.contractor@libertyglobal.com>
2020-09-02 15:37:16 +02:00
Eren ATAS 15ee9899b8 Added property-multiline for parameterized build trigger plugin
Updated test cases as well, The tag has been introduced after 2.35.2
therefore the parameter is also >=2.35.2

Change-Id: Ie0801108a16969b420b341e2deaa6ba62deb116c
Signed-off-by: Eren ATAS <eatas.contractor@libertyglobal.com>
2020-07-31 14:12:00 +02:00
Zuul c5fac510f2 Merge "Fix Authorization Matrix property - inheritance strategy" 2020-07-17 13:55:00 +00:00
Zuul fd85f34754 Merge "Updated GHPRB plugin support" 2020-07-15 14:13:53 +00:00
Adam Romanek 703a76650f Fix Authorization Matrix property - inheritance strategy
Up until now <inheritanceStrategy> tag was only added to jobs-in-a-folder
and folder configs. In JJB the tag's class is always set to
"InheritParentStrategy" which according to the docs means the "item will
inherit its parent items permissions". Apparently <inheritanceStrategy>
tag needs to be present on top-level jobs also. For top-level jobs
setting the tag's class value to "InheritParentStrategy" means the job
"will inherit the global security security settings" and this is the
default behavior.

The code has simplified a bit - if it's a folder then we use a different
property name for authorization matrix property, other than that the
code is the same for all three "variants": folder, job-in-a-folder and
job-outside-a-folder (top-level job).

Also this change fixes the missing <inheritanceStrategy> tag for
job-in-a-folder, where the folder name was specified as part of the
"name" key instead of the standalone "folder" key. With this change we
no longer check if a job is in a folder or not, so it's implicitly
fixed. Added a test case to catch potential regressions in the future.

The copyright notice reflects this and the previous contribution in this
module.

Change-Id: I84b22c09c8a107aab2b4eca20feffc9b61675a92
2020-07-15 13:11:33 +02:00
Eren ATAS 2e84bdf5b6 Removed the unnecessary empty combinationFilter Tag
In the current implementation, jjb creates an empty
combinationFilter tag whenever there is `executionStrategy`.
This empty tag should not appear.

Change-Id: I2bf25ae58d12904ce0a00e0a5cfefbf27d9451ad
Signed-off-by: Eren ATAS <eatas.contractor@libertyglobal.com>
2020-07-07 11:32:51 +02:00
Eren ATAS 987dbc4d2b Updated GHPRB plugin support
Implemented the following tags that have been missing:
- displayBuildErrorsOnDownstreamBuilds
- blackListCommitAuthor
- GhprbCommentFile
- GhprbNoCommitStatus

Following tags are printed when the value of the key is empty:
    - whiteListTargetBranches
    - blackListTargetBranches
    - buildDescTemplate
    - triggeredStatus
    - startedStatus
    - statusUrl
    - addTestResults

Also updated tests

Change-Id: I1e19841d88728af9ac6aa9e1c78f89fe962a583f
Signed-off-by: Eren ATAS <eatas.contractor@libertyglobal.com>
2020-07-07 11:20:46 +02:00
Adam Romanek b04ca3a82c Gerrit Trigger: update support to the latest plugin version
The changes include:

- deprecated the following options and made support for them dependent
  on the Gerrit Trigger plugin version:
  - 'no-name-and-email'
  - 'readable-message'
  - 'trigger-for-unreviewed-patches'

- added a set of new options:
  - 'name-and-email-parameter-mode' (replaced 'no-name-and-email')
  - 'commit-message-parameter-mode' (replaced 'readable-message')
  - 'change-subject-parameter-mode'
  - 'comment-text-parameter-mode'
  all these options can have one of the following values:
  - NONE
  - PLAIN
  - BASE64
  the default value for the first two options is taken from the
  respective options they replaced, if they exist in the input YAML
  file, so the overall change should be backward compatible

- fixed the value generated for <dynamicTriggerConfiguration> element
  it should be "true"/"false" instead of "True"/"False"

- added an empty <dynamicGerritProjects> element when dynamic trigger
  functionality is disabled to match what the plugin does

With the above changes the markup generated by JJB is fully aligned with
Gerrit Trigger plugin v2.30.x. Tested on Gerrit Trigger plugin v2.30.0.

Task: 39871
Story: 2007722
Change-Id: I25800874f51a93a351926a9a1be255cce80b88bd
2020-06-01 15:39:18 +02:00
Zuul 2b238d656d Merge "Pipelines: stop producing unsupported and deprecated XML tags" 2020-05-25 19:36:55 +00:00
Adam Romanek 8625fe2a97 Pipelines: stop producing unsupported and deprecated XML tags
The changes include:
- <concurrentBuild> should now be represented as
  <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
  property
- <triggers> should now be localed inside
  <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
  property, in <properties> section
- unsupported XML elements got removed:
  - <blockBuildWhenDownstreamBuilding>
  - <blockBuildWhenUpstreamBuilding>
  - <assignedNode>
  - <canRoam>
  - <customWorkspace>
- got rid of publishers from project_pipeline_template005.{xml,yaml} as
  these are not supported in Pipeline jobs

The above changes align the produced XMLs with the ones from Jenkins 2.190.1
and Pipeline plugin v2.6.

Task: 39836
Story: 2007708

Change-Id: I650ef2ee60e872cce8f93de5f391933d68ec81f0
2020-05-25 13:59:13 +02:00
Igor Lakhtenkov 2eb74a15cd Added trim option for String parameter.
Task: #22637
Change-Id: Ic2722aac586d3911e3ff5ab4c2d3c5a7a03fa14e
2020-05-22 17:04:49 +03:00
Adam Romanek 074985c7ff Fix Authorization Matrix property support on jobs in a folder
Without the fix:

> 2020-05-11 10:56:12.238+0000 [id=29522]	WARNING
> o.e.j.s.h.ContextHandler$Context#log: Error while serving http://localhost/job/someFolder/createItem
> java.lang.ClassCastException: com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty cannot be cast to hudson.model.JobProperty

It turns out com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty
should only be applied to Folders, not Jobs. The latter should use
hudson.security.AuthorizationMatrixProperty.

Task: 39760
Story: 2007666

Change-Id: I64907265b214fb1e489e1e657a30c90d6ee08c3f
2020-05-13 14:16:45 +02:00
Artem Nikitin ad94757a4a Fix authorization property issue
The change fixes a XML generating error (KeyError: '_use_folder_perms')
for project, which isn't contained in a folder and has got authorization
properties.

Task: 38110
Story: 2007087

Change-Id: I2e0ec6e524d07a935333b35e10eb4204af9256f7
2020-01-17 09:55:59 +03:00
James Harris 8c19ca0cd2 Fix double inderection of name templates
Ensure that we can resolve any lazily loaded templates that might be
dictionary keys in yaml. For more informmation please see the added test
case in tests/yamlparser/fixtures/jinja-string04.yaml.

Change-Id: I67fbca422f2165729af15e4d039278ad66f6240b
Story: 2006431
Task: 36338
2019-11-05 23:33:57 -06:00
James Harris b27399c477 Allow use of jinja templates in defaults
Jinja templates are not deep-copyable so they cannot be used in
"defautls" sections or to pick defualts for job groups or projects.

This works around the issue by waiting until we render the template to
construct the template itself.

Story: 2006431
Task: 36337
Change-Id: Ief31fdaac06bb14d0aaba71c8c0e658a7f861671
2019-11-05 20:18:28 -06:00
Jo Rhett 895d8f3f7a Fix Authorization properties for folder and job in Folder
This outputs the correct XML schema for authorization properties for
  both a folder, and a job inside a folder.
Story: 2006493
Story: 2006611

Change-Id: I14662855613ce146f74b85f5978a0ed828f4439b
2019-10-02 12:07:13 -07:00
Daniel Watkins 63c02a8092
Revert "Add support for rendering jinja template as yaml"
This reverts commit a9e12ed4a9.

Change-Id: I2bbb2cc167a4c2cd95ac6b376ebe83bcf7a263ad
2019-07-29 14:41:52 -04:00
Philip Roche a9e12ed4a9 Add support for rendering jinja template as yaml
This also adds support for using custom loaders in job definitions

not just job-templates and builders. I have also added unit tests for include-jinja2-as-yaml custom loader.

Example usage:

        - axis:
            type: user-defined
            name: VERSIONS
            values:
                !include-jinja2-as-yaml: versions.j2.yaml.inc

Where versions.j2.yaml.inc is

{% for possible_versions in configuration["possible_versions"] %}
- {{ possible_versions["versions"] }}
{% endfor -%}

Change-Id: I15a431d5a86b29d704efda8576965ade2b7dcd2f
2019-07-12 17:58:40 +01:00
Thanh Ha 02e85408f0
Fix default '0' being ignored
The problem with `if default:` is that it evaluates int 0 to be
equivalent to False. If a user is passing in a int 0 then they
should be expected to receive int 0 in the case of defaults.

Change-Id: Ida1f4c68b6f9d1af5b98d633b552f038c57654cc
Signed-off-by: Thanh Ha <zxiiro@linux.com>
2018-12-05 17:59:12 +08:00
Daniel Belenky 3806c9c3d7 Handle cancel-builds-on-update values from vars
The code assumes that the value of cancel-builds-on-update is a boolean.
This fails when specifying the value of the param in a variable because when
deep_formatter formats the data, booleans turn into strings.

Also added tests for such case.

Change-Id: Ib1ec3d5545091be550bfe023e49c7982372d5b55
Signed-off-by: Daniel Belenky <daniel.belenky@gmail.com>
2018-11-14 10:47:36 +02:00
Sorin Sbarnea 4953756c27
adopt pre-commit hooks
Change-Id: I98bc0b5717c3921b35e74f53c55f896427880a84
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2018-07-12 13:40:38 +01:00
Sorin Sbarnea c2781e670f
Normalize newlines at end of file
Preparatory move for adopting pre-commit hooks.
Shoudl only remove newlines and spaces at end of files.

Change-Id: Ia33679467c533722b9308f7e7b74be395c926428
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2018-06-29 16:07:06 -04:00
Sorin Sbarnea 14011df16e
Symlink folders001.xml to deduplicate the test xml
Change-Id: Id03b1a147303cc377a48be25ba93f97cab856a8c
Co-Authored-By: Thanh Ha <thanh.ha@linuxfoundation.org>
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
2018-06-29 09:17:50 -04:00
Zuul 7611778a10 Merge "add pipeline template using nested stage command" 2018-06-21 17:42:12 +00:00
Tomas Hartmann ff2d631d1a Add trigger-from-child-projects option.
Update trigger-parameterized-job arguments, to include
trigger from child projects.

Closes-Bug: story/2002157
Change-Id: Iae0610ee942dd2cad95e3fcaa8b70b16f42b3c50
2018-06-08 09:06:39 +00:00
Anushka Bhandari 741ce73fa6 add pipeline template using nested stage command
Change-Id: I52bbf54c5c1c2603473b36f362b42e9291976543
Story: #2001759
Task: #12157
2018-05-23 06:09:06 +00:00
Martin Kopec 1b7555309f Fix default value regex pattern
Negative values can't be set as default values
currently, for example:
num-to-keep: '{num_to_keep|-1}'
It will return an exception saying: 'parameter missing
to format'.

This should also allow other patterns as long they do
not contain the closing curly bracket.

Change-Id: I26dafb80b120f2c071dda6d9a27319d533b0f874
2018-05-22 20:45:58 +00:00
Thanh Ha 90663ea8a6
Document use of | character for variable defaults
Change-Id: Id20fc7a49fef6684170a73834f2df06db3f0ca7f
Signed-off-by: Thanh Ha <zxiiro@linux.com>
2018-04-13 13:38:07 -04:00
Darragh Bailey 13df88774a Add helper tag to join arbitrary lists into strings
Adds a yaml application tag '!join:' to support defining data as a list
while having the resulting contents automatically joined together with
the specified delimiter and passed as a string into the resulting object
returned by yaml for JJB to process.

This allows users to store long lists of data that is combined together
for use with Jenkins plugins that expect a delimited string of arguments
instead of needing each module in JJB to provide individual support.

Change-Id: I745181ade3926d5c29708963189ae499a0378ece
2018-04-12 20:36:44 +01:00
Andrew Mellen 9d540666b2 Added code for lightweight-checkout
Implements: lightweight-checkout for pipeline projects
Closes-Story: #2001717
Change-Id: I9bd63fba9a8f199e6b8c467c072d9804a44ec45d
2018-03-22 09:00:50 -04:00
Marco Nenciarini ca5d12627f Fix duplicated actions field in XML for folders
Change-Id: I9638dda0c31dfd70ffe8fcfc9eecc260bb326f61
2018-02-27 17:52:24 +00:00
Zuul 70685b5dfe Merge "Always deep format Jinja2 templates" 2018-02-24 16:31:13 +00:00
Daniel Watkins aa74f8d67c Add support for {% include %} in Jinja2 templates
This allows the use of the {% include %} tag[0] within Jinja2 templates,
with the same search path used for looking up other templates (i.e. the
one which LocalLoader is instantiated with).

[0] http://jinja.pocoo.org/docs/2.9/templates/#include

Change-Id: I0403c385ee317e1460a80a9bf717aa4712f37e2f
2018-02-23 12:04:45 -05:00
Daniel Watkins ac7bcb5337 Always deep format Jinja2 templates
As Jinja2 provides functionality other than interpolation, it's entirely
feasible to use it outside of a context where there are template
variables.  This change ensures that we always deep format Jinja2
templates, even when we wouldn't normally interpolate a regular JJB
template.

Change-Id: Ia3f86dd2073d48594eaf791fa2277db7e5ebf0ab
2018-02-23 11:43:21 -05:00
Daniel Watkins d6c8111f66 Add !j2 directive to allow inline Jinja2 templates
This enables the use of Jinja2 templating within strings in the template
YAML files.

Change-Id: I2e912d2f874c5f2428e1aed4af94897aee8d4a72
2018-02-21 20:49:22 -05:00
Zuul a601f54f2f Merge "Fix the formatter regex" 2018-02-09 16:44:28 +00:00
Zuul ed07d8fa94 Merge "Fix timeout wrapper version detection" 2018-02-08 20:55:26 +00:00