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

Set Env Variables for SCM with Checkout SCM

    XMLWordPrintable

Details

    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

            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 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 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 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
            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?

            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?
            abayer Andrew Bayer added a comment -

            markewaite - 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.

            abayer Andrew Bayer added a comment - markewaite - 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.

            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.

            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.

            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

            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
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

            People

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

              Dates

                Created:
                Updated:
                Resolved: