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

"when changeset" not working in P4 multibranch pipeline with Windows Jenkins Master

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Blocker Blocker
    • p4-plugin
    • Jenkins 2.203
      P4-Plugin 1.10.6

      I am following this recent example and it does not seem to work for multibranch P4. All of the echo commands show that the changeset information is fully available, but the when changeset conditional never passes:

      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}"               }
                  }
                 }
              }
            }
      

      Results:

      [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

      Is this a bug?

          [JENKINS-60066] "when changeset" not working in P4 multibranch pipeline with Windows Jenkins Master

          Jesse Rapczak created issue -
          Jesse Rapczak made changes -
          Description Original: I am following this recent example and it does not seem to work for multibranch P4. All of the echo commands show that the changeset information is fully available, but the when changeset conditional never passes:
           stage("Test changeset"){
           when
          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}" }
                      }
                     }
                  }
                }
          Results:
          {noformat}
          [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{noformat}
          Is this a bug?
          New: I am following this recent example and it does not seem to work for multibranch P4. All of the echo commands show that the changeset information is fully available, but the when changeset conditional never passes:
          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}" }
                      }
                     }
                  }
                }
          Results:
          {noformat}
          [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{noformat}
          Is this a bug?
          Jesse Rapczak made changes -
          Description Original: I am following this recent example and it does not seem to work for multibranch P4. All of the echo commands show that the changeset information is fully available, but the when changeset conditional never passes:
          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}" }
                      }
                     }
                  }
                }
          Results:
          {noformat}
          [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{noformat}
          Is this a bug?
          New: I am following this recent example and it does not seem to work for multibranch P4. All of the echo commands show that the changeset information is fully available, but the when changeset conditional never passes:

          {noformat}
          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}" }
                      }
                     }
                  }
                }
          {noformat}

          Results:
          {noformat}
          [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{noformat}
          Is this a bug?

          Karl Wirth added a comment -

          Hi jrapczak,

          Thanks for highlighting this. I'll test here and get back to you with my findings.

          Karl Wirth added a comment - Hi jrapczak , Thanks for highlighting this. I'll test here and get back to you with my findings.
          Karl Wirth made changes -
          Assignee New: Karl Wirth [ p4karl ]
          Karl Wirth made changes -
          Link New: This issue is related to JENKINS-58441 [ JENKINS-58441 ]

          Karl Wirth added a comment - - edited

          Note: Original testing for pipeline and changeset was in JENKINS-58441.

          Karl Wirth added a comment - - edited Note: Original testing for pipeline and changeset was in JENKINS-58441 .

          Karl Wirth added a comment -

          Hi jrapczak,

           for me if I submit the 'Jenkinsfile' to '//streams/main/Jenkinsfile' worked when I selected the sub branch (main) and chose 'Build now':

           

          [Pipeline] { (Test changeset)
          [Pipeline] echo
          The changeset test worked!!
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Run script)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] echo
          2094 by super on Wed Nov 06 17:43:54 UTC 2019: Edited
          [Pipeline] echo
            edit //streams/main/Jenkinsfile
          [Pipeline] echo
          P4_CHANGELIST is NOW:
          [Pipeline] echo
          2094
          

          This was with P4-Plugin 1.10.6 but Jenkins 1.176.1.

          Are you running the test in the same way (build now) ? If you are then maybe it's Jenkins version related.

           

          Note that I don't fully understand the Jenkins 'when' and 'changeset' syntax but I managed to refine my script so that it can match when I submit any file to the path '//streams/main/sub/...':

          when { changeset "//streams/main/sub/**"}
              steps{ echo "You submitted to //streams/main/sub/..."}
          

          or any file under any 'sub' directory:

           when { changeset "**/sub/**"} 
               steps{ echo "You submitted to //.../sub/..."}
          

           

          Karl Wirth added a comment - Hi jrapczak ,  for me if I submit the 'Jenkinsfile' to '//streams/main/Jenkinsfile' worked when I selected the sub branch (main) and chose 'Build now':   [Pipeline] { (Test changeset) [Pipeline] echo The changeset test worked!! [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Run script) [Pipeline] script [Pipeline] { [Pipeline] echo 2094 by super on Wed Nov 06 17:43:54 UTC 2019: Edited [Pipeline] echo edit //streams/main/Jenkinsfile [Pipeline] echo P4_CHANGELIST is NOW: [Pipeline] echo 2094 This was with P4-Plugin 1.10.6 but Jenkins 1.176.1. Are you running the test in the same way (build now) ? If you are then maybe it's Jenkins version related.   Note that I don't fully understand the Jenkins 'when' and 'changeset' syntax but I managed to refine my script so that it can match when I submit any file to the path '//streams/main/sub/...': when { changeset " //streams/main/sub/**" } steps{ echo "You submitted to //streams/main/sub/..." } or any file under any 'sub' directory: when { changeset "**/sub/**" } steps{ echo "You submitted to //.../sub/..." }  
          Karl Wirth made changes -
          Labels Original: p4-plugin pipeline New: P4_SUPPORT p4-plugin pipeline

          Jesse Rapczak added a comment - - edited

          I run it the same way you are, but I am on Jenkins 2.203. Are you able to test with that? I'm not sure how I could easily roll back our Jenkins to an earlier 1.X version but I can look into setting up a separate test environment if you are unable to check with latest. I will actually try to roll back to the latest LTS release anyway (2.190.2).

          Jesse

          Jesse Rapczak added a comment - - edited I run it the same way you are, but I am on Jenkins 2.203. Are you able to test with that? I'm not sure how I could easily roll back our Jenkins to an earlier 1.X version but I can look into setting up a separate test environment if you are unable to check with latest. I will actually try to roll back to the latest LTS release anyway (2.190.2). Jesse

            Unassigned Unassigned
            jrapczak Jesse Rapczak
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: