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

COPYARTIFACT_BUILD_NUMBER_SUFFIX for pipelines (aka. workflow jobs)

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • copyartifact-plugin
    • None
    • jenkins 1.655

      Does the COPYARTIFACT_BUILD_NUMBER_SUFFIX work on expected lines in workflow/pipeline jobs? copy artifact command am using is

      step([$class: 'CopyArtifact', filter: '*.rpm', fingerprintArtifacts: true, projectName: 'test_pkg', resultVariableSuffix: 'testsuffix', selector: [$class: 'ParameterizedBuildSelector', parameterName: 'testparam'], target: 'test_packages'])

      when i do

      println COPYARTIFACT_BUILD_NUMBER_TESTSUFFIX

      am getting the below error

      groovy.lang.MissingPropertyException: No such property: COPYARTIFACT_BUILD_NUMBER_TESTSUFFIX for class: WorkflowScript

      println env.COPYARTIFACT_BUILD_NUMBER_TESTSUFFIX gives me null

          [JENKINS-34620] COPYARTIFACT_BUILD_NUMBER_SUFFIX for pipelines (aka. workflow jobs)

          ikedam added a comment -

          Technically, COPYARTIFACT_BUILD_NUMBER_SUFFIX are implemented with EnvironmentContoributorAction.
          But pipeline (aka. workflow) doesn't work with EnvironmentContributorAction (Please also see JENKINS-29537).

          Possible solutions in future:

          • Pipeline supports EnvironmentContributorAction
          • Copyartifact provides an alternate way for pipelines to detect the build from where artifacts are copied.
            • I don't know much about pipelines, and don't know an appropriate solution.

          ikedam added a comment - Technically, COPYARTIFACT_BUILD_NUMBER_SUFFIX are implemented with EnvironmentContoributorAction. But pipeline (aka. workflow) doesn't work with EnvironmentContributorAction (Please also see JENKINS-29537 ). Possible solutions in future: Pipeline supports EnvironmentContributorAction Copyartifact provides an alternate way for pipelines to detect the build from where artifacts are copied. I don't know much about pipelines, and don't know an appropriate solution.

          ikedam added a comment -

          ikedam added a comment - Related https://groups.google.com/d/msgid/jenkinsci-dev/1644147.f1qsRL37a5%40linux

          Lyndon Washington added a comment - - edited

          So is this issue that you cannot access the 'COPYARTIFACT_BUILD_NUMBER_SUFFIX' environment variable from within a pipeline build at all, or that if you are using the CopyArtifact plugin within a pipeline job to retrieve from another pipeline job, then the environment variable is not available?

          Lyndon Washington added a comment - - edited So is this issue that you cannot access the 'COPYARTIFACT_BUILD_NUMBER_SUFFIX' environment variable from within a pipeline build at all, or that if you are using the CopyArtifact plugin within a pipeline job to retrieve from another pipeline job, then the environment variable is not available?

          Andrew Meyer added a comment - - edited

          I would love this feature. For pipelines/workflows, couldn't you just store it into a local variable rather than an environment variable? Similar to how this plugin works.

          In the meantime, we get around this by uploading a file in the source job called `buildNumber.txt` (generated by `sh "echo ${env.BUILD_NUMBER} > buildNumber.txt"), then using the `StatusBuildSelector` in the destination job to download the file from the last successful (or stable) build. Then `readFile` into a local variable.

          Andrew Meyer added a comment - - edited I would love this feature. For pipelines/workflows, couldn't you just store it into a local variable rather than an environment variable? Similar to how this plugin works. In the meantime, we get around this by uploading a file in the source job called `buildNumber.txt` (generated by `sh "echo ${env.BUILD_NUMBER} > buildNumber.txt"), then using the `StatusBuildSelector` in the destination job to download the file from the last successful (or stable) build. Then `readFile` into a local variable.

          Rene Buergel added a comment - - edited

          This is actually the feature i'm looking for. I want to get the build number in a (declarative) pipeline job.

          Any ideas how to do that without modifiying the artifacts in the source job as supposed by Andrew, about three years later?

          unfortunately, COPYARTIFACT_BUILD_NUMBER_XXX is still not set.

          Rene Buergel added a comment - - edited This is actually the feature i'm looking for. I want to get the build number in a (declarative) pipeline job. Any ideas how to do that without modifiying the artifacts in the source job as supposed by Andrew, about three years later? unfortunately, COPYARTIFACT_BUILD_NUMBER_XXX is still not set.

          Maybe the following snippet helps?

                  stage("Get artifacts") {
                      copyArtifacts filter: artifactsToCopy,
                                  projectName: upstreamJob,
                                  fingerprintArtifacts: true,
                                  selector: specific(buildNumberToUse),
                                  target: 'artifacts_in/'
          
                      def upstreamJobHttpPath = upstreamJob.replaceAll("/", "/job/")
                      httpRequest url: 'http://frinavci01.strykercorp.com:8080/' + upstreamJobHttpPath + '/' + buildNumberToUse + '/api/json', outputFile: 'output.json'
                      def jsonFileContent = readFile(file: 'output.json')
                      def data = readJSON text: jsonFileContent
                      def buildNumber = "${data.number}"
          
                      currentBuild.description = "7z #${buildNumber} -> ${nameOfCartToDeployTo}"
                  }
          

          Heiko Nardmann added a comment - Maybe the following snippet helps? stage( "Get artifacts" ) { copyArtifacts filter: artifactsToCopy, projectName: upstreamJob, fingerprintArtifacts: true , selector: specific(buildNumberToUse), target: 'artifacts_in/' def upstreamJobHttpPath = upstreamJob.replaceAll( "/" , "/job/" ) httpRequest url: 'http: //frinavci01.strykercorp.com:8080/' + upstreamJobHttpPath + '/' + buildNumberToUse + '/api/json' , outputFile: 'output.json' def jsonFileContent = readFile(file: 'output.json' ) def data = readJSON text: jsonFileContent def buildNumber = "${data.number}" currentBuild.description = "7z #${buildNumber} -> ${nameOfCartToDeployTo}" }

            Unassigned Unassigned
            kishorerp kishorerp
            Votes:
            8 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: