Last active
October 19, 2018 07:13
-
-
Save aurimasbachanovicius/289f18e45b02a8aaae7dfae4859c85cd to your computer and use it in GitHub Desktop.
Jenkins Pipeline Groovy function to execute a command with changed files as argument. Can be used for linters which must check only changed files between stages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NonCPS | |
def executeCommandWithFiles(command) { | |
def changeLogSets = currentBuild.changeSets | |
def filesString = "" | |
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] | |
def files = new ArrayList(entry.affectedFiles) | |
for (int k = 0; k < files.size(); k++) { | |
def file = files[k] | |
filesString += " ${file.path}" | |
} | |
} | |
} | |
def cmd = "${command} ${filesString}" | |
sh "${cmd}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
stages { | |
stage('Code Quality') { | |
steps { | |
"PHP Code Sniffer" : { | |
ansiColor('xterm') { | |
executeCommandWithFiles("---script for code sniffer which accepts arguments as files---") | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment