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

Allow passing earlier build numbers to downstream jobs

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      We build some assets in phase 1, then use those assets in phase 2. We are using the Copy Artifacts plugin.

      We cannot use the "build that triggered this build" as phase 1 doesn't trigger phase 2.

      We cannot use "most recent build" as we run the multijob in parallel with itself.

      To work around this, we are using the attachment and the EnvInject plugin to find the previous build number and the pass that to the "specific build" option for artifacts.

        Attachments

          Activity

          Hide
          maruska Michal Maruska added a comment -

          I have tried this workaround:

          a MJ invokes A (build), B (test), C (post-process the output of tests). C needs to access the artifacts of B.

          So, in C I'd try to use the groovy script to inject Env. But InjEnv seems to use shell script only.

          Build Environment > Inject environment variables to the build process

          Even Build > Inject environment variables > Properties Content does not mention Groovy.

          So, I don't know how/where to use that groovy script.

          Show
          maruska Michal Maruska added a comment - I have tried this workaround: a MJ invokes A (build), B (test), C (post-process the output of tests). C needs to access the artifacts of B. So, in C I'd try to use the groovy script to inject Env. But InjEnv seems to use shell script only. Build Environment > Inject environment variables to the build process Even Build > Inject environment variables > Properties Content does not mention Groovy. So, I don't know how/where to use that groovy script.
          Hide
          maruska Michal Maruska added a comment -

          I installed Groovy plugin, and used the code as System Groovy script (build step).
          I get this error:

          [EnvInject] - Loading node environment variables.
          Building on master in workspace /var/lib/jenkins/workspace/fake-post-process
          FATAL: No such property: currentBuild for class: Script1
          groovy.lang.MissingPropertyException: No such property: currentBuild for class: Script1
          	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
          	at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
          	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
          	at Script1.run(Script1.groovy:6)
          	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:682)
          	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:666)
          	at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:81)
          	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
          	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:781)
          	at hudson.model.Build$BuildExecution.build(Build.java:199)
          	at hudson.model.Build$BuildExecution.doRun(Build.java:160)
          	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:562)
          	at hudson.model.Run.execute(Run.java:1679)
          	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
          	at hudson.model.ResourceController.execute(ResourceController.java:88)
          	at hudson.model.Executor.run(Executor.java:230)
          
          Show
          maruska Michal Maruska added a comment - I installed Groovy plugin, and used the code as System Groovy script (build step). I get this error: [EnvInject] - Loading node environment variables. Building on master in workspace /var/lib/jenkins/workspace/fake-post-process FATAL: No such property: currentBuild for class: Script1 groovy.lang.MissingPropertyException: No such property: currentBuild for class: Script1 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231) at Script1.run(Script1.groovy:6) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:682) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:666) at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:81) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:781) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:160) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:562) at hudson.model.Run.execute(Run.java:1679) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:230)
          Hide
          maruska Michal Maruska added a comment -

          so, inside the MJ I can get the build_number of B with this System Groovy script:

          import jenkins.*;
          import jenkins.model.*;
          
          def previousSiblingProjectName = "B";
          
          def assetBuild = build.builders.find { subBuild ->
            subBuild.jobName == previousSiblingProjectName
          }
          
          return [PREV_JOB_BUILD_NUMBER: assetBuild.buildNumber];
          

          Where B is the job invoked (not the stage name).

          Show
          maruska Michal Maruska added a comment - so, inside the MJ I can get the build_number of B with this System Groovy script: import jenkins.*; import jenkins.model.*; def previousSiblingProjectName = "B" ; def assetBuild = build.builders.find { subBuild -> subBuild.jobName == previousSiblingProjectName } return [PREV_JOB_BUILD_NUMBER: assetBuild.buildNumber]; Where B is the job invoked (not the stage name).
          Hide
          yorammi Yoram Michaeli added a comment -

          Closing issue as part of tikal-multijob-plugin issues cleanup.
          If still relevant, please open a matching issue in https://github.com/jenkinsci/tikal-multijob-plugin/issues (you can refer to this issue in its description)

          Show
          yorammi Yoram Michaeli added a comment - Closing issue as part of tikal-multijob-plugin issues cleanup. If still relevant, please open a matching issue in https://github.com/jenkinsci/tikal-multijob-plugin/issues (you can refer to this issue in its description)

            People

            • Assignee:
              Unassigned
              Reporter:
              shepmaster Jake Goulding
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: