Created
July 11, 2018 09:49
-
-
Save atward/ca414f25627ceddc62de77532e8270f2 to your computer and use it in GitHub Desktop.
Jenkins scan config & generate stages
This file contains hidden or 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
def jobs = ["JobA", "JobB", "JobC"] | |
def parallelStagesMap = jobs.collectEntries { | |
["${it}" : generateStage(it)] | |
} | |
def generateStage(job) { | |
return { | |
stage("stage: ${job}") { | |
echo "This is ${job}." | |
sh script: "sleep 15" | |
} | |
} | |
} | |
pipeline { | |
agent any | |
stages { | |
stage('non-parallel stage') { | |
steps { | |
echo 'This stage will be executed first.' | |
} | |
} | |
stage('parallel stage') { | |
steps { | |
script { | |
parallel parallelStagesMap | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
def jq_script_get_config_files = """.provisioners[] | | |
if .type == "file" then .source | |
elif .type == "shell" then .script | |
else null | |
end | |
| strings""" | |
// get list of files used by each config | |
used_files_per_config = [:] | |
def configs = findFiles(glob: 'config/*.json') | |
configs.each { | |
def pk_config = "${it}" | |
def jq_get_used = ["jq", "-r", jq_script_get_config_files, pk_config].execute() | |
jq_get_used.waitFor() | |
def used_files = [ pk_config, *jq_get_used.in.text.split("\n") ] | |
//println(used_files) | |
used_files_by_config[pk_config] = used_files | |
} | |
// get list of files changed | |
def cmd = "git diff --name-only ${LAST_KNOWN_GOOD_COMMIT} ${GIT_COMMIT}".execute() | |
cmd.waitFor() | |
def git_changed_files = cmd.in.text.split("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment