From 134b0c75b34c7c0afa1d738dae4c969b5bec1c3e Mon Sep 17 00:00:00 2001 From: Olev Kartau Date: Fri, 24 Feb 2017 14:19:17 +0200 Subject: [PATCH] CI Jenkinsfile: publish results regardless of build phase status Sometimes detailed build logs contain important information which gets lost after failed build phase because we stop the pipeline. Let's run publish part always, trying to copy out whatever we can. Publish script needs another check for workdir existence to handle all states without trouble. Make detailed logs publish mask more exact to exclude irrelevant logs. --- Jenkinsfile | 32 +++++++++++++++++++------------- docker/publish-project.sh | 6 ++++-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 43db4bf998..4d1a8c4425 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -125,21 +125,27 @@ try { timestamps { sshagent(['github-auth-ssh']) { docker_image.inside(run_args) { - stage('Bitbake Build') { - if (is_pr) { - setGitHubPullRequestStatus state: 'PENDING', context: "${env.JOB_NAME}", message: "Bitbake Build" + try { + stage('Bitbake Build') { + if (is_pr) { + setGitHubPullRequestStatus state: 'PENDING', context: "${env.JOB_NAME}", message: "Bitbake Build" + } + params = ["${script_env}", + "docker/build-project.sh"].join("\n") + sh "${params}" } - params = ["${script_env}", - "docker/build-project.sh"].join("\n") - sh "${params}" - } - stage('Build publishing') { - if (is_pr) { - setGitHubPullRequestStatus state: 'PENDING', context: "${env.JOB_NAME}", message: "Build publishing" + } catch (Exception e) { + throw e + } finally { + // publish in finally-block so that detailed logs or any partial results get stored even in case of failed build + stage('Build publishing') { + if (is_pr) { + setGitHubPullRequestStatus state: 'PENDING', context: "${env.JOB_NAME}", message: "Build publishing" + } + params = ["${script_env}", + "docker/publish-project.sh"].join("\n") + sh "${params}" } - params = ["${script_env}", - "docker/publish-project.sh"].join("\n") - sh "${params}" } } } // sshagent diff --git a/docker/publish-project.sh b/docker/publish-project.sh index 8f23cd1266..84cffc89b9 100755 --- a/docker/publish-project.sh +++ b/docker/publish-project.sh @@ -132,8 +132,10 @@ fi # Copy detailed build logs # Include symlinks to avoid massive amount of "skipping non-regular file" # lines in the rsyncd server system-level log -create_remote_dirs ${_RSYNC_DEST} detailed-logs/${TARGET_MACHINE}/ -rsync -qzrl --prune-empty-dirs --include "log.*" --include "*/" --exclude "*" ${_BRESULT}/work*/* ${_RSYNC_DEST}/detailed-logs/${TARGET_MACHINE}/ +if [ -d ${_BRESULT}/work ]; then + create_remote_dirs ${_RSYNC_DEST} detailed-logs/${TARGET_MACHINE}/ + rsync -qzrl --prune-empty-dirs --include "log.do_*" --include "*/" --exclude "*" ${_BRESULT}/work*/* ${_RSYNC_DEST}/detailed-logs/${TARGET_MACHINE}/ +fi # Create latest symlink locally and rsync it to parent dir of publish dir ln -vsf ${CI_BUILD_ID} latest