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

copyArtifacts 'filter' parameter does not allow whitespace

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      In pipeline step documentation, reading about copyArtifact 'filter'  (https://www.jenkins.io/doc/pipeline/steps/copyartifact/):

      > Can use wildcards like module/dist/*/.zip, and use comma (followed by optional whitespace) to separate multiple entries.

       

      Turns out using space after comma no longer works and terminates the filter.

       

      Example (whitespaced):

      copyArtifacts fingerprintArtifacts: true, flatten: true, projectName: 'foo', selector: lastSuccessful(stable: true), target: '.', filter: '**/module*.json, **/group*.json'
      sh('ls')

      Result:

      module_1.json 
      module_2.json 
      module_3.json 
      module_4.json
      

      Example 2 (no witespace):

      copyArtifacts fingerprintArtifacts: true, flatten: true, projectName: 'foo', selector: lastSuccessful(stable: true), target: '.', filter: '**/module*.json,**/group*.json'
      sh('ls')

      Result 2:

      module_1.json
      module_2.json
      module_3.json
      module_4.json
      group_1.json
      group_2.json
      group_3.json
      

       

      Version observed: copyartifact-1.46.1

        Attachments

          Activity

          Hide
          ikedam ikedam added a comment -

          Couldn't reproduce with the following test code (equivalent to copyartifact-1.46.1):

              @Test
              public void testBlankInFilter() throws Exception {
                  FreeStyleProject src = rule.createFreeStyleProject();
                  src.getBuildersList().add(new FileWriteBuilder("module_1.json", "{\"foobar\":\"buzz\"}"));
                  src.getBuildersList().add(new FileWriteBuilder("group_1.json", "{\"foobar\":\"buzz\"}"));
                  src.getPublishersList().add(new ArtifactArchiver("*.json"));
                  rule.assertBuildStatusSuccess(src.scheduleBuild2(0));
          
                  FreeStyleProject dest = rule.createFreeStyleProject();
                  dest.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
                          src.getName(),
                          "",
                          new StatusBuildSelector(true),
                          "**/module*.json, **/group*.json",
                          "",
                          false,
                          false,
                          true
                  ));
                  FreeStyleBuild b = dest.scheduleBuild2(0, new UserCause()).get();
                  rule.assertBuildStatusSuccess(b);
                  assertFile(true, "module_1.json", b);
                  assertFile(true, "group_1.json", b);
              }
          

          I have to test more:

          • It might behave differently with the lastest Jenkins core. The above code is tested with Jenkins-2.164.3, which copyartifact targets.
          • It might behave differently with pipelines. The above code is tested with freestyle jobs.
          • It might behave differently with the latest Java. The above code is tested with Java8.

          It would be helpful if you describe:

          • More details about your environment, for example, versions of OS, Java and Jenkins.
          • The version of copyartifact (and environments) where spaces after comma worked.
          Show
          ikedam ikedam added a comment - Couldn't reproduce with the following test code (equivalent to copyartifact-1.46.1): @Test public void testBlankInFilter() throws Exception { FreeStyleProject src = rule.createFreeStyleProject(); src.getBuildersList().add( new FileWriteBuilder( "module_1.json" , "{\" foobar\ ":\" buzz\ "}" )); src.getBuildersList().add( new FileWriteBuilder( "group_1.json" , "{\" foobar\ ":\" buzz\ "}" )); src.getPublishersList().add( new ArtifactArchiver( "*.json" )); rule.assertBuildStatusSuccess(src.scheduleBuild2(0)); FreeStyleProject dest = rule.createFreeStyleProject(); dest.getBuildersList().add(CopyArtifactUtil.createCopyArtifact( src.getName(), "", new StatusBuildSelector( true ), "**/module*.json, **/group*.json" , "", false , false , true )); FreeStyleBuild b = dest.scheduleBuild2(0, new UserCause()).get(); rule.assertBuildStatusSuccess(b); assertFile( true , "module_1.json" , b); assertFile( true , "group_1.json" , b); } I have to test more: It might behave differently with the lastest Jenkins core. The above code is tested with Jenkins-2.164.3, which copyartifact targets. It might behave differently with pipelines. The above code is tested with freestyle jobs. It might behave differently with the latest Java. The above code is tested with Java8. It would be helpful if you describe: More details about your environment, for example, versions of OS, Java and Jenkins. The version of copyartifact (and environments) where spaces after comma worked.
          Hide
          ikedam ikedam added a comment -

          Cannot reproduce in my environment:

          • Start new Jenkins instance
            docker run --rm -it -p 8080:8080 jenkins/jenkins:2.289.2-lts-alpine
            
          • Setup Jenkins installing following plugins:
            • Pipeline
            • Copy Artifact
              • 1.46.1 was installed.
          • Create a pipeline named "src":
            pipeline {
              agent any
              options {
                copyArtifactPermission('dest')
              }
              stages {
                stage('run') {
                  steps {
                    dir('sub1') {
                      writeFile file: 'module_1.json', text: 'module1'
                    }
                    dir('sub2') {
                      writeFile file: 'group_1.json', text: 'group1'
                    }
                    archive includes: 'sub1/module_1.json,sub2/group_1.json'
                  }
                }
              }
            }
            
          • Run a build for src.
          • Create a pipeline named "dest":
            pipeline {
              agent any
              stages {
                stage('run') {
                  steps {
                    copyArtifacts fingerprintArtifacts: true, flatten: true, projectName: 'src', selector: lastSuccessful(stable: true), target: '.', filter: '**/module*.json, **/group*.json'
                    sh('ls')
                  }
                }
              }
            }
            
          • Run a build for dest.
          • See the output from the build.

          Result:

          Started by user admin
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] node
          Running on Jenkins in /var/jenkins_home/workspace/dest
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (run)
          [Pipeline] copyArtifacts
          Copied 2 artifacts from "src" build number 2
          [Pipeline] sh
          + ls
          group_1.json
          module_1.json
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          
          Show
          ikedam ikedam added a comment - Cannot reproduce in my environment: Start new Jenkins instance docker run --rm -it -p 8080:8080 jenkins/jenkins:2.289.2-lts-alpine Setup Jenkins installing following plugins: Pipeline Copy Artifact 1.46.1 was installed. Create a pipeline named "src": pipeline { agent any options { copyArtifactPermission( 'dest' ) } stages { stage( 'run' ) { steps { dir( 'sub1' ) { writeFile file: 'module_1.json' , text: 'module1' } dir( 'sub2' ) { writeFile file: 'group_1.json' , text: 'group1' } archive includes: 'sub1/module_1.json,sub2/group_1.json' } } } } Run a build for src. Create a pipeline named "dest": pipeline { agent any stages { stage( 'run' ) { steps { copyArtifacts fingerprintArtifacts: true , flatten: true , projectName: 'src' , selector: lastSuccessful(stable: true ), target: '.' , filter: '**/module*.json, **/group*.json' sh( 'ls' ) } } } } Run a build for dest. See the output from the build. Result: Started by user admin Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in / var /jenkins_home/workspace/dest [Pipeline] { [Pipeline] stage [Pipeline] { (run) [Pipeline] copyArtifacts Copied 2 artifacts from "src" build number 2 [Pipeline] sh + ls group_1.json module_1.json [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS

            People

            Assignee:
            filip_daca Filip
            Reporter:
            filip_daca Filip
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: