Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-36780 Pipeline support #5

Open
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

drekbour
Copy link

Complete rework of #3. This adds the technical ability to apply templating to pipeline jobs (WorkflowJob) with a distinct set exclusions from the the classic project (AbstractProject) mode.

It does not answer much about the impact of doing this so will sit as a WIP even if integrated into master until we're a bit more certain of the end-to-end flow.

juanpablo-santos and others added 30 commits October 5, 2016 13:55
… both AbstractProject and WorkflowJob. Propagate the necessary changes to make it compile (there are still some references to AbtractProject that have to be replaced)
…eas jenkins.version is also set in parent, and inline with other plugins inheriting same parent (there's a profile in there to use 1.580.3)
2.- EzMatchers.java: use Job instead of AbstractProject, rename HasImplmentations to HasImplementations
3.- BehaviourTest.java: impl_finds_known_templates needs to call descriptor.isApplicable, so doFillTemplateJobNameItems() knows which types of jobs to look for
…ethod so the check is done every time.

2.- make the code non-dependent of workflow plugin. In order to avoid cluttering the code, use a new method at EzReflectionUtils to handle the isAssignable calls
…*all* changes from upstream master

2.- EzMatchers.java: use Job instead of AbstractProject, rename HasImplmentations to HasImplementations
3.- BehaviourTest.java: impl_finds_known_templates needs to call descriptor.isApplicable, so doFillTemplateJobNameItems() knows which types of jobs to look for
4.- PromotedBuildsTemplateUtils: move original method to private mergePromotions, and also make use of EzReflectionUtils.isAssignable instead of direct class.isAssignable so this kind of call is always done the same way
… to run normally if the workflow-job plugin isn't installed. Added more methods at EzReflectionUtils so the JobsFacade code isn't cluttered with reflection code
Marc Carter added 18 commits November 6, 2016 12:55
Conflicts:
	pom.xml
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/AssignedLabelExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/DescriptionExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/DisabledExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/Exclusions.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/EzTemplatesExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/HardCodedExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/JobParametersExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/JobPropertyExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/MatrixAxisExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/ScmExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/exclusion/TriggersExclusion.java
	src/main/java/com/joelj/jenkins/eztemplates/promotedbuilds/PromotedBuildsTemplateUtils.java
	src/main/java/com/joelj/jenkins/eztemplates/utils/ProjectUtils.java
	src/main/java/com/joelj/jenkins/eztemplates/utils/TemplateUtils.java
	src/main/resources/com/joelj/jenkins/eztemplates/AbstractTemplateImplementationProperty/config-details.jelly
	src/test/java/com/joelj/jenkins/eztemplates/BehaviourTest.java
	src/test/java/com/joelj/jenkins/eztemplates/exclusion/ExclusionUtilTest.java
Still not perfect but reduces the number of classes in each package. Also added BackwardsCompatiblity for pre-existing config.xmls that contain the old class-names
In 2.32.2, SaveableListener allowed much better templating by making use of BulkChange class to suppress events before "commit". We now baseline beyond this change so will assume it.
Avoid classloading errors if pipeline is not installed
@drekbour
Copy link
Author

As an example, a pipeline with parameters as below will set ParametersDefinitionProperty each time it is run (note run not saved)

pipeline {
    agent any

    parameters {
        booleanParam(defaultValue: true, description: '', name: 'userFlag')
    }

    stages {
        stage("foo") {
            steps {
                echo "flag: ${params.userFlag}"
            }
        }
    }
}
<hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.BooleanParameterDefinition>
          <name>userFlag</name>
          <description></description>
          <defaultValue>true</defaultValue>
        </hudson.model.BooleanParameterDefinition>

The interaction with EZT merging ParametersDefinitionProperty on save with pipeline doing so on run is a bit weird. It's further complicated by the distinction of inline script (held as a JobProperty) or a committed Jenkinsfile. Frankly - I think ETZ cannot work safely with a Jenkinsfile

@drekbour
Copy link
Author

@juanpablo-santos @jxramos You had opinions on this previously, can you tell me a little about how you think this 'works'

@juanpablo-santos
Copy link

Hi @drekbour,

apologies for the late response, Christmas caught up with me :-) Haven't been able to look at the code yet but, said that, pipelines from templated jobs shouldn't define parameters themselves, but use those defined at the job level: parameters defined at pipeline level cannot be templated, whereas those defined at job level can, being that the main use for EZT for pipeline jobs.

None of our pipelines defines parameters, so we haven't come across the ParametersDefinitionProperty being set on each job run. In any case, I agree, it is weird, the plugin should be able to detect an omit those cases.

EZT should somehow omit doing anything if the parameter is defined on a pipeline (the parameter wouldn't be "templatable"), and that would also fix the issue with the plugin doing something on pipeline runs. More precisely, it would be ok for me if the plugin ends up triggered by pipeline runs (because of Jenkins internals or whatever), but the plugin is able to detect this situation, or that the property comes from a pipeline, and do nothing.

Allow me a couple of weeks to take a look at this, and I'll update with whatever I come up with.

br,
juan pablo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants