Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-35698

Initial run of parameterized pipeline build should return properties default value

    XMLWordPrintable

Details

    Description

      colored textOn the first build the config parameter doesn't exist but it'd be great if on this initial build Config parameter could be setup with the default value.

      For example,

      properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', defaultValue: 'Release', description: '', name: 'configParam']]]]) 
      

      So

      binding.hasVariable('configParameter') should return true, and should has the value Release

      Attachments

        Issue Links

          Activity

            jglick Jesse Glick added a comment -

            As shown here there is a workaround which probably just needs to make it into documentation. The requested behavior is not even theoretically possible.

            jglick Jesse Glick added a comment - As shown here there is a workaround which probably just needs to make it into documentation. The requested behavior is not even theoretically possible.
            jglick Jesse Glick added a comment -

            An implementation of JENKINS-27295 using a parameters virtual map could be designed to check for default values in ParametersDefinitionProperty even for keys not mentioned in ParametersAction, which would allow this to work on the first build:

            properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', name: 'mode', defaultValue: 'normal']]]])
            assert parameters.mode == 'normal'
            
            jglick Jesse Glick added a comment - An implementation of JENKINS-27295 using a parameters virtual map could be designed to check for default values in ParametersDefinitionProperty even for keys not mentioned in ParametersAction , which would allow this to work on the first build: properties([[$class: 'ParametersDefinitionProperty' , parameterDefinitions: [[$class: 'StringParameterDefinition' , name: 'mode' , defaultValue: 'normal' ]]]]) assert parameters.mode == 'normal'
            mtraynham Matt Traynham added a comment -

            Hey jglick, your workaround sort of fixes this for initial runs, but it fails when a Jenkinsfile "properties" has changed (maybe from a merge) and a subsequent run will use the old properties. This can cause jobs to fail or have undesired results. I imagine, based on the tutorials I've viewed and my own Jenkinsfile, that properties will likely always come at the beginning of the pipeline. So if the properties function could return a map, I think this would be much more straightforward, rather than injecting them into the binding (not a big Groovy user, but I think that's what it's doing).

            mtraynham Matt Traynham added a comment - Hey jglick , your workaround sort of fixes this for initial runs, but it fails when a Jenkinsfile "properties" has changed (maybe from a merge) and a subsequent run will use the old properties. This can cause jobs to fail or have undesired results. I imagine, based on the tutorials I've viewed and my own Jenkinsfile, that properties will likely always come at the beginning of the pipeline. So if the properties function could return a map, I think this would be much more straightforward, rather than injecting them into the binding (not a big Groovy user, but I think that's what it's doing).
            jglick Jesse Glick added a comment -

            it fails when a Jenkinsfile "properties" has changed […] and a subsequent run will use the old properties

            When properties is run, it changes the properties for the job. In the case of build parameters, these are consulted before the build starts, thus use the parameters defined as of the previous build. This issue is about allowing params to pay attention to the current definition.

            jglick Jesse Glick added a comment - it fails when a Jenkinsfile "properties" has changed […] and a subsequent run will use the old properties When properties is run, it changes the properties for the job. In the case of build parameters, these are consulted before the build starts, thus use the parameters defined as of the previous build. This issue is about allowing params to pay attention to the current definition.

            Code changed in jenkins
            User: Jesse Glick
            Path:
            src/main/java/org/jenkinsci/plugins/workflow/cps/ParamsVariable.java
            src/main/resources/org/jenkinsci/plugins/workflow/cps/ParamsVariable/help.jelly
            http://jenkins-ci.org/commit/workflow-cps-plugin/0161aecc2877ec4c7086c1bce7d0c69f42e6c267
            Log:
            [FIXED JENKINS-35698] Make params offer default parameter values from the current definition as a fallback.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/org/jenkinsci/plugins/workflow/cps/ParamsVariable.java src/main/resources/org/jenkinsci/plugins/workflow/cps/ParamsVariable/help.jelly http://jenkins-ci.org/commit/workflow-cps-plugin/0161aecc2877ec4c7086c1bce7d0c69f42e6c267 Log: [FIXED JENKINS-35698] Make params offer default parameter values from the current definition as a fallback.

            Code changed in jenkins
            User: Jesse Glick
            Path:
            pom.xml
            src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java
            http://jenkins-ci.org/commit/workflow-multibranch-plugin/9acfbdf2144180a7ff2a03efc43f484f157a161b
            Log:
            JENKINS-35698 Integration test for params fallback behavior.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java http://jenkins-ci.org/commit/workflow-multibranch-plugin/9acfbdf2144180a7ff2a03efc43f484f157a161b Log: JENKINS-35698 Integration test for params fallback behavior.

            Code changed in jenkins
            User: Jesse Glick
            Path:
            pom.xml
            src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java
            http://jenkins-ci.org/commit/workflow-multibranch-plugin/56d24dcc10d6decfb6fc2904216543851adb82b4
            Log:
            Merge pull request #36 from jglick/params-default-JENKINS-35698

            JENKINS-35698 Integration test for params fallback behavior

            Compare: https://github.com/jenkinsci/workflow-multibranch-plugin/compare/3f1a413631dc...56d24dcc10d6

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java http://jenkins-ci.org/commit/workflow-multibranch-plugin/56d24dcc10d6decfb6fc2904216543851adb82b4 Log: Merge pull request #36 from jglick/params-default- JENKINS-35698 JENKINS-35698 Integration test for params fallback behavior Compare: https://github.com/jenkinsci/workflow-multibranch-plugin/compare/3f1a413631dc...56d24dcc10d6
            ahuntpindrop Alex Hunt added a comment -

            What version of the plugins is this fixed in? This still seems to be a problem.

            We're using the following plugins:

            ace-editor:1.1
            active-directory:2.0
            ant:1.4
            antisamy-markup-formatter:1.5
            artifactory:2.8.1
            authentication-tokens:1.3
            aws-credentials:1.16
            aws-java-sdk:1.11.37
            bouncycastle-api:2.16.0
            branch-api:1.11.1
            build-timeout:1.18
            cloudbees-folder:5.13
            cobertura:1.9.8
            conditional-buildstep:1.3.5
            config-file-provider:2.13
            credentials:2.1.10
            credentials-binding:1.10
            cucumber-testresult-plugin:0.9.7
            datadog:0.5.5
            display-url-api:0.5
            docker-commons:1.5
            docker-custom-build-environment:1.6.5
            docker-workflow:1.9.1
            durable-task:1.12
            ec2:1.36
            email-ext:2.52
            embeddable-build-status:1.9
            envinject:1.93.1
            external-monitor-job:1.6
            git:3.0.1
            git-client:2.1.0
            github:1.24.0
            github-api:1.80
            github-branch-source:1.10.1
            github-organization-folder:1.5
            git-server:1.7
            global-build-stats:1.4
            gradle:1.25
            handlebars:1.1.1
            htmlpublisher:1.11
            icon-shim:2.0.3
            ivy:1.26
            jackson2-api:2.7.3
            javadoc:1.4
            jquery-detached:1.2.1
            junit:1.19
            ldap:1.13
            mailer:1.18
            mapdb-api:1.0.9.0
            matrix-auth:1.4
            matrix-project:1.7.1
            maven-plugin:2.14
            momentjs:1.1.1
            node-iterator-api:1.5
            pam-auth:1.3
            parallel-test-executor:1.9
            parameterized-trigger:2.32
            pipeline-build-step:2.4
            pipeline-graph-analysis:1.2
            pipeline-input-step:2.5
            pipeline-milestone-step:1.2
            pipeline-rest-api:2.3
            pipeline-stage-step:2.2
            pipeline-stage-view:2.3
            plain-credentials:1.3
            resource-disposer:0.3
            run-condition:1.0
            scm-api:1.3
            script-security:1.24
            slack:2.1
            ssh-agent:1.13
            ssh-credentials:1.12
            ssh-slaves:1.11
            structs:1.5
            subversion:2.7.1
            swarm:2.2
            timestamper:1.8.7
            token-macro:2.0
            windows-slaves:1.2
            workflow-aggregator:2.4
            workflow-api:2.6
            workflow-basic-steps:2.3
            workflow-cps:2.23
            workflow-cps-global-lib:2.5
            workflow-durable-task-step:2.5
            workflow-job:2.9
            workflow-multibranch:2.9.2
            workflow-scm-step:2.3
            workflow-step-api:2.5
            workflow-support:2.11
            ws-cleanup:0.32
            
            ahuntpindrop Alex Hunt added a comment - What version of the plugins is this fixed in? This still seems to be a problem. We're using the following plugins: ace-editor:1.1 active-directory:2.0 ant:1.4 antisamy-markup-formatter:1.5 artifactory:2.8.1 authentication-tokens:1.3 aws-credentials:1.16 aws-java-sdk:1.11.37 bouncycastle-api:2.16.0 branch-api:1.11.1 build-timeout:1.18 cloudbees-folder:5.13 cobertura:1.9.8 conditional-buildstep:1.3.5 config-file-provider:2.13 credentials:2.1.10 credentials-binding:1.10 cucumber-testresult-plugin:0.9.7 datadog:0.5.5 display-url-api:0.5 docker-commons:1.5 docker-custom-build-environment:1.6.5 docker-workflow:1.9.1 durable-task:1.12 ec2:1.36 email-ext:2.52 embeddable-build-status:1.9 envinject:1.93.1 external-monitor-job:1.6 git:3.0.1 git-client:2.1.0 github:1.24.0 github-api:1.80 github-branch-source:1.10.1 github-organization-folder:1.5 git-server:1.7 global-build-stats:1.4 gradle:1.25 handlebars:1.1.1 htmlpublisher:1.11 icon-shim:2.0.3 ivy:1.26 jackson2-api:2.7.3 javadoc:1.4 jquery-detached:1.2.1 junit:1.19 ldap:1.13 mailer:1.18 mapdb-api:1.0.9.0 matrix-auth:1.4 matrix-project:1.7.1 maven-plugin:2.14 momentjs:1.1.1 node-iterator-api:1.5 pam-auth:1.3 parallel-test-executor:1.9 parameterized-trigger:2.32 pipeline-build-step:2.4 pipeline-graph-analysis:1.2 pipeline-input-step:2.5 pipeline-milestone-step:1.2 pipeline-rest-api:2.3 pipeline-stage-step:2.2 pipeline-stage-view:2.3 plain-credentials:1.3 resource-disposer:0.3 run-condition:1.0 scm-api:1.3 script-security:1.24 slack:2.1 ssh-agent:1.13 ssh-credentials:1.12 ssh-slaves:1.11 structs:1.5 subversion:2.7.1 swarm:2.2 timestamper:1.8.7 token-macro:2.0 windows-slaves:1.2 workflow-aggregator:2.4 workflow-api:2.6 workflow-basic-steps:2.3 workflow-cps:2.23 workflow-cps-global-lib:2.5 workflow-durable-task-step:2.5 workflow-job:2.9 workflow-multibranch:2.9.2 workflow-scm-step:2.3 workflow-step-api:2.5 workflow-support:2.11 ws-cleanup:0.32
            jglick Jesse Glick added a comment - - edited

            workflow-cps 2.19. ahuntpindrop please do not reopen. If you believe you have found a bug, file separately with complete, self-contained steps to reproduce from scratch.

            jglick Jesse Glick added a comment - - edited workflow-cps 2.19. ahuntpindrop please do not reopen. If you believe you have found a bug, file separately with complete, self-contained steps to reproduce from scratch.
            ahuntpindrop Alex Hunt added a comment -

            jglick Thank you for your response. https://issues.jenkins-ci.org/browse/JENKINS-40235

            This seems identical to this ticket and JENKINS-37330. In fact, I just copied the example from that one.

            ahuntpindrop Alex Hunt added a comment - jglick Thank you for your response. https://issues.jenkins-ci.org/browse/JENKINS-40235 This seems identical to this ticket and JENKINS-37330 . In fact, I just copied the example from that one.

            People

              jglick Jesse Glick
              escoem Emilio Escobar
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: