• Icon: Task Task
    • Resolution: Fixed
    • Icon: Major Major
    • p4-plugin
    • None

      Hi,

       

      Is it possible to use changeset syntax ?

       

      For example,

      stage ('test') {
        when {
          changeset "branchA/folder1/**"
        }
        steps {
          ...
        }
      }

          [JENKINS-58441] can I use changeset in when pipeline syntax

          Karl Wirth added a comment -

          Hi luckyhorang - Yes but I do not know how useful it will be. The following uses 'changeset' to test for the 'Jenkinsfile':

           

          pipeline {  agent { label 'master' }  stages {
             stage("Test changeset"){
                  when { changeset "**/Jenkinsfile"}
                      steps{ echo "The changeset test worked!!"}
                  }
              stage("Display changeset?") {
                steps {
                  script {
                     def changeLogSets = currentBuild.changeSets
                     for (int i = 0; i < changeLogSets.size(); i++) {
                     def entries = changeLogSets[i].items
                     for (int j = 0; j < entries.length; j++) {
                         def entry = entries[j]
                         echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
                         def files = new ArrayList(entry.affectedFiles)
                         for (int k = 0; k < files.size(); k++) {
                             def file = files[k]
                             echo " ${file.editType.name} ${file.path}"
                         }
                      }
                     }
                  }
                }
          
          

          Note that the text at the end attempts to display the contents of the changeset. In my case the output was:

          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Test changeset)
          [Pipeline] echo
          The changeset test worked!!
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Display changeset?)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] echo
          1734 by super on Thu Jul 11 16:39:02 UTC 2019: Edited
          [Pipeline] echo
            edit //streams/main/Jenkinsfile
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          

          I did not understand the changeset regex syntax so you may have to ask others about that.

           

          Karl Wirth added a comment - Hi luckyhorang - Yes but I do not know how useful it will be. The following uses 'changeset' to test for the 'Jenkinsfile':   pipeline { agent { label 'master' } stages { stage( "Test changeset" ){ when { changeset "**/Jenkinsfile" } steps{ echo "The changeset test worked!!" } } stage( "Display changeset?" ) { steps { script { def changeLogSets = currentBuild.changeSets for ( int i = 0; i < changeLogSets.size(); i++) { def entries = changeLogSets[i].items for ( int j = 0; j < entries.length; j++) { def entry = entries[j] echo "${entry.commitId} by ${entry.author} on ${ new Date(entry.timestamp)}: ${entry.msg}" def files = new ArrayList(entry.affectedFiles) for ( int k = 0; k < files.size(); k++) { def file = files[k] echo " ${file.editType.name} ${file.path}" } } } } } Note that the text at the end attempts to display the contents of the changeset. In my case the output was: [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Test changeset) [Pipeline] echo The changeset test worked!! [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Display changeset?) [Pipeline] script [Pipeline] { [Pipeline] echo 1734 by super on Thu Jul 11 16:39:02 UTC 2019: Edited [Pipeline] echo edit //streams/main/Jenkinsfile [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS I did not understand the changeset regex syntax so you may have to ask others about that.  

          Hokwang Lee added a comment -

          Thanks. You can close this case.

          Hokwang Lee added a comment - Thanks. You can close this case.

          Karl Wirth added a comment -

          Hi luckyhorang - Thanks.

          Karl Wirth added a comment - Hi luckyhorang - Thanks.

          Jesse Rapczak added a comment - - edited

          I'm trying to get this exact example working in a multibranch pipeline, and the when test exactly as written above is failing for some reason despite the other stuff looking OK... any ideas?

          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Test changeset)
          Stage "Test changeset" skipped due to when conditional
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Display changeset?)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] echo
          66 by jesse on Tue Nov 05 03:40:41 PST 2019: Polling time adjust
          [Pipeline] echo
           edit //streams/Dev-Jenkins/Jenkinsfile
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          

          Jesse Rapczak added a comment - - edited I'm trying to get this exact example working in a multibranch pipeline, and the when test exactly as written above is failing for some reason despite the other stuff looking OK... any ideas? [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Test changeset) Stage "Test changeset" skipped due to when conditional [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Display changeset?) [Pipeline] script [Pipeline] { [Pipeline] echo 66 by jesse on Tue Nov 05 03:40:41 PST 2019: Polling time adjust [Pipeline] echo edit //streams/Dev-Jenkins/Jenkinsfile [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage

          Karl Wirth added a comment -

          See JENKINS-60066 for investigation.

          Karl Wirth added a comment - See JENKINS-60066 for investigation.

            Unassigned Unassigned
            luckyhorang Hokwang Lee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: