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

Set Env Variables for SCM with Checkout SCM

    Details

    • Similar Issues:

      Description

      Now that JENKINS-26100 has been resolved we should bake this into Declarative, too.

      This works fine in Scripted to set all scm properties into env variables:

      checkout(scm).each { k,v -> env.setProperty(k, v) }

      We should build this into Declarative by default.

       

        Attachments

          Issue Links

            Activity

            hrmpw Patrick Wolf created issue -
            Hide
            abayer Andrew Bayer added a comment -

            Sadly, we can't do this 'til Declarative depends on core 2.60 or later, so it'll be a while.

            Show
            abayer Andrew Bayer added a comment - Sadly, we can't do this 'til Declarative depends on core 2.60 or later, so it'll be a while.
            abayer Andrew Bayer made changes -
            Field Original Value New Value
            Link This issue is duplicated by JENKINS-45223 [ JENKINS-45223 ]
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            Hide
            abayer Andrew Bayer added a comment -

            Figured out a way to get this working for anyone with the right core/etc versions without needing to update dependencies. It'll keep not doing anything if checkout scm doesn't return anything, but if it does, it'll use that map to populate the environment. PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/177

            Show
            abayer Andrew Bayer added a comment - Figured out a way to get this working for anyone with the right core/etc versions without needing to update dependencies. It'll keep not doing anything if checkout scm doesn't return anything, but if it does, it'll use that map to populate the environment. PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/177
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "PR #177 (Web Link)" [ 17413 ]
            Hide
            markewaite Mark Waite added a comment -

            That is great news.

            Will the results of multiple checkout operations (repository A to root of workspace, repository B to subdirectory B of workspace, etc.) be combined into a single set of environment variables, or will there be some other way of getting the SHA1 of both repository A and repository B in a declarative pipeline?

            Show
            markewaite Mark Waite added a comment - That is great news. Will the results of multiple checkout operations (repository A to root of workspace, repository B to subdirectory B of workspace, etc.) be combined into a single set of environment variables, or will there be some other way of getting the SHA1 of both repository A and repository B in a declarative pipeline?
            Hide
            abayer Andrew Bayer added a comment -

            Mark Waite - so this will only apply to the implicit checkout scm that happens behind the scenes, so it'll just be the one repository that the Declarative Pipeline Jenkinsfile is in. Also, it won't kick in until on an agent, so if you have agent none at the top level, the env vars won't be available until you're in a stage with an agent.

            Show
            abayer Andrew Bayer added a comment - Mark Waite - so this will only apply to the implicit checkout scm that happens behind the scenes, so it'll just be the one repository that the Declarative Pipeline Jenkinsfile is in. Also, it won't kick in until on an agent, so if you have agent none at the top level, the env vars won't be available until you're in a stage with an agent.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
            pipeline-model-definition/src/test/resources/scmEnvVars.groovy
            pipeline-model-extensions/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/e75cf195fa6d9fb4972911284718d682e6bd3888
            Log:
            [FIXED JENKINS-45198] When possible, add scm vars to environment

            This will not result in any change when run on core versions <2.60 (or
            with workflow-scm-step <2.6, git <3.3.1, etc), but will Just Work if
            you've got the right core/etc versions installed.

            BasicModelDefTest#scmEnvVars will start failing when we bump core etc
            dependencies for this plugin directly.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java pipeline-model-definition/src/test/resources/scmEnvVars.groovy pipeline-model-extensions/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/e75cf195fa6d9fb4972911284718d682e6bd3888 Log: [FIXED JENKINS-45198] When possible, add scm vars to environment This will not result in any change when run on core versions <2.60 (or with workflow-scm-step <2.6, git <3.3.1, etc), but will Just Work if you've got the right core/etc versions installed. BasicModelDefTest#scmEnvVars will start failing when we bump core etc dependencies for this plugin directly.
            abayer Andrew Bayer made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/pom.xml
            pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/SyntheticStageGraphListener.java
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
            pipeline-model-definition/src/test/resources/scmEnvVars.groovy
            pipeline-model-extensions/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy
            pom.xml
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/eafc831f586bb7992fc5eaed5c9889cc26e09ea2
            Log:
            Merge pull request #177 from abayer/jenkins-45198

            [FIXED JENKINS-45198] When possible, add scm vars to environment

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/pom.xml pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/SyntheticStageGraphListener.java pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java pipeline-model-definition/src/test/resources/scmEnvVars.groovy pipeline-model-extensions/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy pom.xml http://jenkins-ci.org/commit/pipeline-model-definition-plugin/eafc831f586bb7992fc5eaed5c9889cc26e09ea2 Log: Merge pull request #177 from abayer/jenkins-45198 [FIXED JENKINS-45198] When possible, add scm vars to environment
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.
            bitwiseman Liam Newman made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                hrmpw Patrick Wolf
              • Votes:
                1 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: