Use a bash wrapper. Compile the report with the standard output from all the executed actions.
This commit is contained in:
parent
7bd5d0808a
commit
451474974a
|
@ -34,6 +34,7 @@ pipeline {
|
|||
AGENT_ROOT_FOLDER = "${agent_root_folder}"
|
||||
PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}"
|
||||
ACTION_REPORT = "${agent_root_folder}/actions.${env.BUILD_NUMBER}.csv"
|
||||
ACTION_OUTPUT = "${agent_root_folder}/action-output.${env.BUILD_NUMBER}.txt"
|
||||
ACTION_URL="${actionURL}"
|
||||
REPO_ROOT="${git_root}"
|
||||
|
||||
|
@ -74,7 +75,7 @@ pipeline {
|
|||
for (int i = 0; i < projects.size(); i++) {
|
||||
stage(projects[i]) {
|
||||
echo "About to execute over ${projects[i]}"
|
||||
checkout_and_exec(projects[i], action_code)
|
||||
checkout_and_exec(projects[i])
|
||||
sh "echo -e ${projects[i]},${git_root}/${projects[i]},Completed >> $ACTION_REPORT"
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +91,8 @@ pipeline {
|
|||
sh '''
|
||||
cp $ACTION_REPORT ./actions.${PIPELINE_BUILD_NUMBER}.csv
|
||||
cat ./actions.${PIPELINE_BUILD_NUMBER}.csv
|
||||
cp $ACTION_OUTPUT ./action-output.${PIPELINE_BUILD_NUMBER}.txt
|
||||
cat ./action-output.${PIPELINE_BUILD_NUMBER}.txt
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +120,7 @@ pipeline {
|
|||
* Clones the repository and executes the fragment
|
||||
* NOTE: 'credentialsId' be manually configured in Jenkins to access all the repos
|
||||
*/
|
||||
def checkout_and_exec(repo_name, actions) {
|
||||
def checkout_and_exec(repo_name) {
|
||||
def repo_url = "${git_root}/${repo_name}"
|
||||
sh(script: "rm -r ${repo_name} || true", returnStdout: true)?.trim()
|
||||
checkout([
|
||||
|
@ -137,7 +140,7 @@ def checkout_and_exec(repo_name, actions) {
|
|||
get_last_commit(repo_name)
|
||||
|
||||
//exec the action
|
||||
exec(actions, repo_url, repo_name)
|
||||
exec(repo_url, repo_name)
|
||||
|
||||
}
|
||||
|
||||
|
@ -152,13 +155,13 @@ String get_last_commit(repo_name) {
|
|||
/**
|
||||
Execs the bash fragment
|
||||
*/
|
||||
def exec(actions, repo_url, repo_name) {
|
||||
|
||||
def exec(repo_url, repo_name) {
|
||||
def output = '';
|
||||
dir(repo_name) {
|
||||
withCredentials([usernamePassword(credentialsId: '88b54962-1c0e-49cb-8155-22276860f346', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
|
||||
def complete_url = "${repo_url}.git"
|
||||
def repository = complete_url.replaceFirst(".+://", "https://${GIT_USERNAME}:${GIT_PASSWORD}@")
|
||||
output = sh(script: """
|
||||
def bashWrapper = """
|
||||
git remote set-url origin $repository
|
||||
git remote -v
|
||||
git config user.email "git.gcube@localhost"
|
||||
|
@ -168,9 +171,14 @@ def exec(actions, repo_url, repo_name) {
|
|||
source actions.sh
|
||||
rm actions.sh
|
||||
git push --force origin HEAD:master || true
|
||||
"""), returnStdout: true)?.trim()
|
||||
"""
|
||||
output = sh(script: bashWrapper, returnStdout: true)
|
||||
}
|
||||
}
|
||||
sh "echo -e --- STDOUT FROM REPO ${repo_url} --- >> $ACTION_OUTPUT"
|
||||
sh "echo -e ${output} >> $ACTION_OUTPUT"
|
||||
sh "echo -e --- END REPO ${repo_url} --- >> $ACTION_OUTPUT"
|
||||
|
||||
}
|
||||
|
||||
//a non CPS method is necessary for the usage of splitEachLine()
|
||||
|
|
Loading…
Reference in New Issue