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

0 views
Skip to first unread message

luckyhk.lee@samsung.com (JIRA)

unread,
Jul 11, 2019, 9:27:02 AM7/11/19
to jenkinsc...@googlegroups.com
Hokwang Lee created an issue
 
Jenkins / Task JENKINS-58441
can I use changeset in when pipeline syntax
Issue Type: Task Task
Assignee: Unassigned
Components: p4-plugin
Created: 2019-07-11 13:26
Priority: Major Major
Reporter: Hokwang Lee

Hi,

 

Is it possible to use changeset syntax ?

 

For example,

stage ('test') {
  when {
    changeset "branchA/folder1/**"
  }
  steps {
    ...
  }
}
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

kwirth@perforce.com (JIRA)

unread,
Jul 11, 2019, 12:48:02 PM7/11/19
to jenkinsc...@googlegroups.com
Karl Wirth commented on Task JENKINS-58441
 
Re: can I use changeset in when pipeline syntax

Hi Hokwang Lee - 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.

 

luckyhk.lee@samsung.com (JIRA)

unread,
Sep 16, 2019, 8:45:01 AM9/16/19
to jenkinsc...@googlegroups.com

Thanks. You can close this case.

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

kwirth@perforce.com (JIRA)

unread,
Sep 20, 2019, 5:20:03 AM9/20/19
to jenkinsc...@googlegroups.com
Karl Wirth resolved as Fixed
 
Change By: Karl Wirth
Status: Open Resolved
Resolution: Fixed

kwirth@perforce.com (JIRA)

unread,
Sep 20, 2019, 5:20:03 AM9/20/19
to jenkinsc...@googlegroups.com

jesse@studiowildcard.com (JIRA)

unread,
Nov 5, 2019, 7:30:03 AM11/5/19
to jenkinsc...@googlegroups.com

I'm trying to get this exact example working, and the when test 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] echo66 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@studiowildcard.com (JIRA)

unread,
Nov 5, 2019, 7:34:02 AM11/5/19
to jenkinsc...@googlegroups.com
Jesse Rapczak edited a comment on Task JENKINS-58441
I'm trying to get this exact example working, and the when test is failing for some reason despite the other stuff looking OK... any ideas?

{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] echo66 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}

jesse@studiowildcard.com (JIRA)

unread,
Nov 5, 2019, 4:07:04 PM11/5/19
to jenkinsc...@googlegroups.com
Jesse Rapczak edited a comment on Task JENKINS-58441
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?


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

kwirth@perforce.com (JIRA)

unread,
Nov 6, 2019, 12:32:02 PM11/6/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages