I used this answer to get a list of changed files in my Jenkins job. My existing Jenkinsfile looks like this:
script {
sshagent(credentials : ['jenkins-bitbucket-lfs']) {
sh '''#!/bin/bash
./build.sh
'''
}
}
If I add the code from the answer above I get the list of changed files. But I can't figure out how to pass the list to my build script one file at a time. I've tried:
script {
// get the list of changed files
changedFiles = []
for (changeLogSet in currentBuild.changeSets) {
for (entry in changeLogSet.getItems()) { // for each commit in the detected changes
for (file in entry.getAffectedFiles()) {
changedFiles.add(file.getPath()) // add changed file to list
}
}
}
echo "Changed files: ${changedFiles}\n"
sshagent(credentials : ['jenkins-bitbucket-lfs']) {
changedFiles.eachWithIndex { item, idx ->
echo "Changed file ${idx}: ${item}\n"
sh '''#!/bin/bash
echo "Changed file = ${item}"
./build.sh ${item}
'''
}
}
}
The file list and invididual file is reported in Groovy, but the parameter is empty in bash. How do I get this to work?