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

COPYARTIFACT_BUILD_NUMBER_SUFFIX for pipelines (aka. workflow jobs)

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: copyartifact-plugin
    • Labels:
      None
    • Environment:
      jenkins 1.655
    • Similar Issues:

      Description

      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

        Attachments

          Activity

          Hide
          ikedam 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.
          Show
          ikedam 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.
          Show
          ikedam ikedam added a comment - Related https://groups.google.com/d/msgid/jenkinsci-dev/1644147.f1qsRL37a5%40linux
          Hide
          hoshposh66 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?

          Show
          hoshposh66 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?
          Hide
          menehune23 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.

          Show
          menehune23 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.
          Hide
          reneb 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.

          Show
          reneb 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.
          Hide
          heiko_nardmann 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}"
                  }
          
          Show
          heiko_nardmann 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}" }

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            kishorerp kishorerp
            Votes:
            7 Vote for this issue
            Watchers:
            14 Start watching this issue

              Dates

              Created:
              Updated: