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

COPYARTIFACT_BUILD_NUMBER_ does not preserve numbers in job names

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            deepchip Martin d'Anjou created issue -
            Hide
            johannsg Johanns Gregorian added a comment -

            This issue is nearly (2) years old, unassigned and without comments.

            I don't know and cannot imagine the technical issue that lead the developers to elect to remove numbers from the name; but the fix is trivial for anyone brave enough to patch and build the plugin from scratch (see below).

            Anyone in the know, please let me know why numbers are removed.

            
            diff --git a/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java b/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
            index 68d0671..4f976ad 100644
            --- a/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
            +++ b/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
            @@ -600,7 +600,7 @@ public class CopyArtifact extends Builder implements SimpleBuildStep {
                             return;
                         }
                         data.put("COPYARTIFACT_BUILD_NUMBER_"
            -                       + projectName.toUpperCase().replaceAll("[^A-Z]+", "_"), // Only use letters and _
            +                       + projectName.toUpperCase().replaceAll("[^A-Z0-9]+", "_"), // Only use alphanumeric and _
                                  Integer.toString(buildNumber));
                     }
            
            
            Show
            johannsg Johanns Gregorian added a comment - This issue is nearly (2) years old, unassigned and without comments. I don't know and cannot imagine the technical issue that lead the developers to elect to remove numbers from the name; but the fix is trivial for anyone brave enough to patch and build the plugin from scratch (see below). Anyone in the know, please let me know why numbers are removed. diff --git a/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java b/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java index 68d0671..4f976ad 100644 --- a/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java +++ b/src/main/java/hudson/plugins/copyartifact/CopyArtifact.java @@ -600,7 +600,7 @@ public class CopyArtifact extends Builder implements SimpleBuildStep { return ; } data.put( "COPYARTIFACT_BUILD_NUMBER_" - + projectName.toUpperCase().replaceAll( "[^A-Z]+" , "_" ), // Only use letters and _ + + projectName.toUpperCase().replaceAll( "[^A-Z0-9]+" , "_" ), // Only use alphanumeric and _ Integer .toString(buildNumber)); }
            mears Josh Davidson made changes -
            Field Original Value New Value
            Priority Major [ 3 ] Blocker [ 1 ]
            Hide
            mears 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.

            Show
            mears 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.
            Hide
            mears 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.

            Show
            mears 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.
            ikedam ikedam made changes -
            Link This issue is related to JENKINS-15764 [ JENKINS-15764 ]
            Hide
            danielbeck 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.

            Show
            danielbeck 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.
            Hide
            danielbeck 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.

            Show
            danielbeck 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 ikedam made changes -
            Link This issue is related to JENKINS-29812 [ JENKINS-29812 ]
            Hide
            ikedam 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.

            Show
            ikedam 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 ikedam made changes -
            Assignee ikedam [ ikedam ]
            ikedam ikedam made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Hide
            scm_issue_link 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

            Show
            scm_issue_link 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
            scm_issue_link SCM/JIRA link daemon made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Hide
            scm_issue_link 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.

            Show
            scm_issue_link 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.
            Hide
            scm_issue_link 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.

            Show
            scm_issue_link 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.
            Hide
            scm_issue_link 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

            Show
            scm_issue_link 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
            Hide
            ikedam 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.

            Show
            ikedam 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 made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 150385 ] JNJira + In-Review [ 206818 ]

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: