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

Run Groovy scripts from files and environment variables

    XMLWordPrintable

Details

    Description

      Currently there is no way to reference external Groovy scripts, they have to be typed in on the job configuration page. It may lead to the same script being duplicated among many jobs, making it difficult to maintain.

      Attachments

        Activity

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/sharedobjects/type/GroovySharedObjectType.java
          src/main/resources/org/jenkinsci/plugins/sharedobjects/type/GroovySharedObjectType/config.jelly
          src/main/resources/org/jenkinsci/plugins/sharedobjects/type/GroovySharedObjectType/help-content.html
          http://jenkins-ci.org/commit/shared-objects-plugin/d295b675c16fabc939f3453e7cc79c1498c8f681
          Log:
          Fix JENKINS-14056

          Compare: https://github.com/jenkinsci/shared-objects-plugin/compare/f3b7183fd19c...d295b675c16f

          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/sharedobjects/type/GroovySharedObjectType.java src/main/resources/org/jenkinsci/plugins/sharedobjects/type/GroovySharedObjectType/config.jelly src/main/resources/org/jenkinsci/plugins/sharedobjects/type/GroovySharedObjectType/help-content.html http://jenkins-ci.org/commit/shared-objects-plugin/d295b675c16fabc939f3453e7cc79c1498c8f681 Log: Fix JENKINS-14056 Compare: https://github.com/jenkinsci/shared-objects-plugin/compare/f3b7183fd19c...d295b675c16f

          Does SharedObjects 0.35 suits you?

          gbois Gregory Boissinot added a comment - Does SharedObjects 0.35 suits you?
          bjagri Balazs Jagri added a comment -

          We need to access build parameters from the Groovy script, apart from that it looks good.

          bjagri Balazs Jagri added a comment - We need to access build parameters from the Groovy script, apart from that it looks good.
          gcummings Geoff Cummings added a comment - - edited

          Hi, thanks for getting the changes in so quickly.

          I also need to access build parameters and environment variables.
          I am still learning about Jenkins and Groovy, but I have found I can access them with the following:

          def thr = Thread.currentThread()
          def build = thr.executable
          // get build parameters
          def buildVariablesMap = build.buildVariables
          // get all environment variables for the build
          def buildEnvVarsMap = build.envVars

          String jobName = buildEnvVarsMap?.JOB_NAME

          Please advise if there is a better way to access this information

          many thanks
          Geoff

          gcummings Geoff Cummings added a comment - - edited Hi, thanks for getting the changes in so quickly. I also need to access build parameters and environment variables. I am still learning about Jenkins and Groovy, but I have found I can access them with the following: def thr = Thread.currentThread() def build = thr.executable // get build parameters def buildVariablesMap = build.buildVariables // get all environment variables for the build def buildEnvVarsMap = build.envVars String jobName = buildEnvVarsMap?.JOB_NAME Please advise if there is a better way to access this information many thanks Geoff

          It is perfect.

          gbois Gregory Boissinot added a comment - It is perfect.

          People

            gbois Gregory Boissinot
            bjagri Balazs Jagri
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: