diff --git a/Jenkinsfile b/Jenkinsfile index 419bd4d..5658f6e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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}.xml" ACTION_URL="${actionURL}" REPO_ROOT="${git_root}" @@ -71,13 +72,16 @@ pipeline { stage('clone and exec') { steps { script { + def start_el = "" + sh "echo -e '${start_el}' >> $ACTION_OUTPUT" 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" } } + sh "echo -e '' >> $ACTION_OUTPUT" } } } @@ -88,23 +92,25 @@ pipeline { always { script { sh ''' - cp $ACTION_REPORT ./actions.${PIPELINE_BUILD_NUMBER}.csv - cat ./actions.${PIPELINE_BUILD_NUMBER}.csv + cp $ACTION_REPORT ./action.${PIPELINE_BUILD_NUMBER}.csv + cat ./action.${PIPELINE_BUILD_NUMBER}.csv + cp $ACTION_OUTPUT ./action-output.${PIPELINE_BUILD_NUMBER}.xml + cat ./action-output.${PIPELINE_BUILD_NUMBER}.xml ''' } } success { echo 'The actions pipeline worked!' - emailext attachmentsPattern: "**/actions.${env.BUILD_NUMBER}.csv", - to: 'manuele.simi@isti.cnr.it', + emailext attachmentsPattern: "**/action*${env.BUILD_NUMBER}.*", + to: 'manuele.simi@isti.cnr.it,roberto.cirillo@isti.cnr.it', subject: "Actions report(build #${PIPELINE_BUILD_NUMBER})", body: "${currentBuild.fullDisplayName}. Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } failure { echo 'The actions pipeline has failed' emailext attachLog: true, - to: 'manuele.simi@isti.cnr.it', + to: 'manuele.simi@isti.cnr.it,roberto.cirillo@isti.cnr.it', subject: "[Jenkins build D4S] build ${currentBuild.fullDisplayName} failed", body: "Something is wrong with ${env.BUILD_URL}" } @@ -117,7 +123,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 +143,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,25 +158,35 @@ 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}@") - sh(""" - git remote set-url origin $repository - git remote -v - git config user.email "git.gcube@localhost" - git config user.name "git.gcube" - curl "${ACTION_URL}" -o actions.sh - chmod a+x actions.sh - source actions.sh - rm actions.sh - git push --force origin HEAD:master || true - """) + def bashWrapper = """ + git remote set-url origin $repository + git remote -v + git config user.email "git.gcube@localhost" + git config user.name "git.gcube" + curl "${ACTION_URL}" -o actions.sh + chmod a+x actions.sh + source actions.sh + rm actions.sh + git push --force origin HEAD:master || true + """ + output = sh(script: bashWrapper, returnStdout: true)?.trim() } } + def xml_action = """ + + + ${output} + + + """ + sh "echo -e '${xml_action}' >> $ACTION_OUTPUT" + } //a non CPS method is necessary for the usage of splitEachLine() diff --git a/README.md b/README.md index c53523f..db4fd5d 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ fi * [Pipeline Syntax](https://jenkins.io/doc/book/pipeline/syntax/) * [Shared Libraries](https://jenkins.io/doc/book/pipeline/shared-libraries/) * [SCM Step](https://jenkins.io/doc/pipeline/steps/workflow-scm-step/) - +* [Workflow Durable Task Step](https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/) ## Wiki doc * [CI: gCube Actions Pipeline](https://wiki.gcube-system.org/gcube/Continuous_Integration:_Actions_Jenkins_Pipeline)