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

COPYARTIFACT_BUILD_NUMBER_ does not preserve numbers in job names

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • copyartifact-plugin
    • None
    • Linux

      The COPYARTIFACT_BUIL_NUMBER_ variable name does not preserve numbers in job names. It removes numbers from job names. For example, if the job is called martin-test1, then the variable name name is: COPYARTIFACT_BUILD_NUMBER_MARTIN_TEST_ (the number has been removed)

      To reproduce:

      1. create a job whose name has a number in it, e.g. martin-test1
      2. run the job once to create some artifacts, and archive them
      3. create another job whose purpose is to copy the artifacts from the first job
      4. in the build phase of the second job, print the environment variables, e.g. with env, and examine the COPYARTIFACT_BUILD_NUMBER_ variable name. It should be missing the numbers

      This was tested in Jenkins 1.524, with version 1.27 of the Copy Artifacts plugin.

          [JENKINS-18938] COPYARTIFACT_BUILD_NUMBER_ does not preserve numbers in job names

          Josh Davidson added a comment -

          I'm assuming the numbers are removed because on some systems, environment variables cannot start with a number. However, the implementation creates difficult to workaround aliasing problems where job names like my_build_win32 and my_build_win64 resolve to same variable (my_build_win_).

          A better implementation that only removes numbers from the start of the variable would be:

          projectName.toUpperCase().replaceAll("^[^A-Z]+", "_").replaceAll("[^A-Z0-9]+", "_") // Variables must begin with a letter (or underscore) and consist of letters, numbers, and _
          

          This prevents invalid variables and should avoid aliasing for 99.5% of job names.

          Josh Davidson added a comment - I'm assuming the numbers are removed because on some systems, environment variables cannot start with a number. However, the implementation creates difficult to workaround aliasing problems where job names like my_build_win32 and my_build_win64 resolve to same variable (my_build_win_). A better implementation that only removes numbers from the start of the variable would be: projectName.toUpperCase().replaceAll( "^[^A-Z]+" , "_" ).replaceAll( "[^A-Z0-9]+" , "_" ) // Variables must begin with a letter (or underscore) and consist of letters, numbers, and _ This prevents invalid variables and should avoid aliasing for 99.5% of job names.

          Josh Davidson added a comment -

          Scratch that. The only time project name is added to an environment variable is when it's appended to a fixed string (COPYARTIFACT_BUILD_NUMBER_), which avoids the problem of starting with a number altogether. So I agree with Johanns, there's no reason to replace numbers.

          Josh Davidson added a comment - Scratch that. The only time project name is added to an environment variable is when it's appended to a fixed string (COPYARTIFACT_BUILD_NUMBER_), which avoids the problem of starting with a number altogether. So I agree with Johanns, there's no reason to replace numbers.

          Daniel Beck added a comment -

          Any change in this will be a breaking change, unfortunately, so it's not as easy as just changing the regex.

          Daniel Beck added a comment - Any change in this will be a breaking change, unfortunately, so it's not as easy as just changing the regex.

          Daniel Beck added a comment -

          What could be done (besides what ikedam suggested in the PR which is actually my favorite option: Define your own env var name), is to define multiple variables. Keep the existing one for backwards compatibility, and also define the one with digits in it.

          Daniel Beck added a comment - What could be done (besides what ikedam suggested in the PR which is actually my favorite option: Define your own env var name), is to define multiple variables. Keep the existing one for backwards compatibility, and also define the one with digits in it.

          ikedam added a comment -

          Created a pull request: https://github.com/jenkinsci/copyartifact-plugin/pull/69
          It introduce a field to specify the suffix to be used instead of the project name.
          Leaving empty have the project name used jest as the current brhavior to keep the backward compatibility.

          ikedam added a comment - Created a pull request: https://github.com/jenkinsci/copyartifact-plugin/pull/69 It introduce a field to specify the suffix to be used instead of the project name. Leaving empty have the project name used jest as the current brhavior to keep the backward compatibility.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/config.jelly
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix.html
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix_ja.html
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-selector.html
          src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
          src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java
          http://jenkins-ci.org/commit/copyartifact-plugin/462bf8f9b7374300e7a8f3b445787fc22d005c4b
          Log:
          [FIXED JENKINS-18938] Added a field to specify the suffix for the variable to store the build number

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/CopyArtifact.java src/main/resources/hudson/plugins/copyartifact/CopyArtifact/config.jelly src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix.html src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix_ja.html src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-selector.html src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java http://jenkins-ci.org/commit/copyartifact-plugin/462bf8f9b7374300e7a8f3b445787fc22d005c4b Log: [FIXED JENKINS-18938] Added a field to specify the suffix for the variable to store the build number

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
          src/main/resources/hudson/plugins/copyartifact/Messages.properties
          src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
          http://jenkins-ci.org/commit/copyartifact-plugin/0f3e11465397b556009a111437bc7b742f31daee
          Log:
          JENKINS-18938 Added validation for the variable suffix.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/CopyArtifact.java src/main/resources/hudson/plugins/copyartifact/Messages.properties src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java http://jenkins-ci.org/commit/copyartifact-plugin/0f3e11465397b556009a111437bc7b742f31daee Log: JENKINS-18938 Added validation for the variable suffix.

          Code changed in jenkins
          User: ikedam
          Path:
          src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java
          http://jenkins-ci.org/commit/copyartifact-plugin/250f8a5c09ad702f09a9a77f670e74d4647a7fd5
          Log:
          JENKINS-18938 Fixed the test failure caused by a wrong change for test utility in the last two commits.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java http://jenkins-ci.org/commit/copyartifact-plugin/250f8a5c09ad702f09a9a77f670e74d4647a7fd5 Log: JENKINS-18938 Fixed the test failure caused by a wrong change for test utility in the last two commits.

          Code changed in jenkins
          User: ikedam
          Path:
          src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/config.jelly
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix.html
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix_ja.html
          src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-selector.html
          src/main/resources/hudson/plugins/copyartifact/Messages.properties
          src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
          src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java
          http://jenkins-ci.org/commit/copyartifact-plugin/ad631aec628fc881bb9becf4586a58952fc5f59c
          Log:
          Merge pull request #69 from ikedam/feature/JENKINS-18938_BuildNumberVariable

          JENKINS-18938 Added a field to specify the suffix for the variable to store the build number

          Compare: https://github.com/jenkinsci/copyartifact-plugin/compare/e68ed44754e2...ad631aec628f

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: ikedam Path: src/main/java/hudson/plugins/copyartifact/CopyArtifact.java src/main/resources/hudson/plugins/copyartifact/CopyArtifact/config.jelly src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix.html src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-resultVariableSuffix_ja.html src/main/resources/hudson/plugins/copyartifact/CopyArtifact/help-selector.html src/main/resources/hudson/plugins/copyartifact/Messages.properties src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java http://jenkins-ci.org/commit/copyartifact-plugin/ad631aec628fc881bb9becf4586a58952fc5f59c Log: Merge pull request #69 from ikedam/feature/ JENKINS-18938 _BuildNumberVariable JENKINS-18938 Added a field to specify the suffix for the variable to store the build number Compare: https://github.com/jenkinsci/copyartifact-plugin/compare/e68ed44754e2...ad631aec628f

          ikedam added a comment -

          Fixed in 1.36, which introduced a field to specify the suffix used instead of the project name.
          It will be available in the update center in a day.
          Please try that.

          ikedam added a comment - Fixed in 1.36, which introduced a field to specify the suffix used instead of the project name. It will be available in the update center in a day. Please try that.

            ikedam ikedam
            deepchip Martin d'Anjou
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: