mirror of
https://github.com/86Box/86Box.git
synced 2025-01-22 09:11:50 -05:00
Jenkins: Trigger deferred failure when any build of any stage fails
This commit is contained in:
parent
eb7a7fed18
commit
015c6b1151
2 changed files with 37 additions and 20 deletions
43
.ci/Jenkinsfile
vendored
43
.ci/Jenkinsfile
vendored
|
@ -48,7 +48,7 @@ def saveArtifacts() {
|
|||
archiveArtifacts artifacts: "${env.JOB_BASE_NAME}-*"
|
||||
}
|
||||
|
||||
def anySuccess = false
|
||||
def successCount = 0
|
||||
|
||||
def buildChain = [
|
||||
'86Box': '86Box-Dev',
|
||||
|
@ -75,32 +75,40 @@ pipeline {
|
|||
|
||||
stages {
|
||||
stage('Build Windows') {
|
||||
agent {
|
||||
node {
|
||||
label 'windows'
|
||||
}
|
||||
}
|
||||
|
||||
steps {
|
||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||
node('windows') {
|
||||
gitClone()
|
||||
windowsBuild()
|
||||
saveArtifacts()
|
||||
}
|
||||
gitClone()
|
||||
windowsBuild()
|
||||
saveArtifacts()
|
||||
|
||||
script {
|
||||
anySuccess = true
|
||||
successCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Linux') {
|
||||
agent {
|
||||
node {
|
||||
label 'debian'
|
||||
}
|
||||
}
|
||||
|
||||
steps {
|
||||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||
node('debian') {
|
||||
gitClone()
|
||||
unixBuild()
|
||||
saveArtifacts()
|
||||
}
|
||||
gitClone()
|
||||
unixBuild()
|
||||
saveArtifacts()
|
||||
|
||||
script {
|
||||
anySuccess = true
|
||||
successCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,11 +118,12 @@ pipeline {
|
|||
post {
|
||||
always {
|
||||
script {
|
||||
/* Trigger next job is applicable. */
|
||||
if (buildChain[env.JOB_BASE_NAME]) {
|
||||
def nextJob = buildChain[env.JOB_BASE_NAME]
|
||||
|
||||
/* Set next build number for the next job. */
|
||||
try {
|
||||
/* Set next build number for this job. */
|
||||
def job = Jenkins.instance.getItem(nextJob)
|
||||
job.nextBuildNumber = env.BUILD_NUMBER as Integer
|
||||
job.saveNextBuildNumber()
|
||||
|
@ -122,7 +131,7 @@ pipeline {
|
|||
println "[!] Could not set next build number for [$nextJob], make sure all required script approvals are in place"
|
||||
}
|
||||
|
||||
/* Trigger this job. */
|
||||
/* Trigger next job. */
|
||||
build propagate: false,
|
||||
wait: false,
|
||||
job: nextJob,
|
||||
|
@ -132,8 +141,8 @@ pipeline {
|
|||
]
|
||||
}
|
||||
|
||||
if (!anySuccess) {
|
||||
println "[!] Failing build because all build stages failed"
|
||||
if (successCount < 2) {
|
||||
println "[!] Failing build because a build stage failed"
|
||||
currentBuild.result = 'FAILURE'
|
||||
}
|
||||
|
||||
|
|
14
.ci/build.sh
14
.ci/build.sh
|
@ -122,6 +122,7 @@ build() {
|
|||
if [ -z "$job_name" ]
|
||||
then
|
||||
echo [!] Missing environment variables: received JOB_BASE_NAME=[$JOB_BASE_NAME] BUILD_TYPE=[$BUILD_TYPE] BUILD_NUMBER=[$BUILD_NUMBER] GIT_COMMIT=[$GIT_COMMIT]
|
||||
job_status=1
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -145,11 +146,12 @@ build() {
|
|||
echo [-] Switching to MSYSTEM [$msys]
|
||||
cd "$cwd"
|
||||
CHERE_INVOKING=yes MSYSTEM="$msys" JOB_BASE_NAME="$JOB_BASE_NAME" BUILD_TYPE="$BUILD_TYPE" BUILD_NUMBER="$BUILD_NUMBER" GIT_COMMIT="$GIT_COMMIT" \
|
||||
bash -lc 'exec "'$0'" -b "'$arch'" '"$cmake_flags" && job_status=0 # make sure the main script exits cleanly on any success
|
||||
bash -lc 'exec "'$0'" -b "'$arch'" '"$cmake_flags"
|
||||
return $?
|
||||
fi
|
||||
else
|
||||
echo [!] No MSYSTEM for architecture [$arch]
|
||||
job_status=1
|
||||
return 2
|
||||
fi
|
||||
echo [-] Using MSYSTEM [$MSYSTEM]
|
||||
|
@ -253,6 +255,7 @@ EOF
|
|||
if [ $? -gt 0 ]
|
||||
then
|
||||
echo [!] CMake failed with status [$status]
|
||||
job_status=1
|
||||
return 3
|
||||
fi
|
||||
|
||||
|
@ -263,6 +266,7 @@ EOF
|
|||
if [ $status -gt 0 ]
|
||||
then
|
||||
echo [!] Make failed with status [$status]
|
||||
job_status=1
|
||||
return 4
|
||||
fi
|
||||
|
||||
|
@ -273,6 +277,7 @@ EOF
|
|||
if [ ! -d "archive_tmp" ]
|
||||
then
|
||||
echo [!] Archive directory creation failed
|
||||
job_status=1
|
||||
return 5
|
||||
fi
|
||||
|
||||
|
@ -337,6 +342,7 @@ EOF
|
|||
if [ $status -gt 0 ]
|
||||
then
|
||||
echo [!] Executable move failed with status [$status]
|
||||
job_status=1
|
||||
return 6
|
||||
fi
|
||||
|
||||
|
@ -363,12 +369,12 @@ EOF
|
|||
if [ $status -gt 0 ]
|
||||
then
|
||||
echo [!] Artifact archive creation failed with status [$status]
|
||||
job_status=1
|
||||
return 7
|
||||
fi
|
||||
|
||||
# All good.
|
||||
echo [-] Build of [$job_name] [$build_type] [$build_qualifier] [$git_hash] for [$arch] with flags [$cmake_flags] successful
|
||||
job_status=0
|
||||
}
|
||||
|
||||
tarball() {
|
||||
|
@ -383,6 +389,7 @@ tarball() {
|
|||
if [ -z "$job_name" ]
|
||||
then
|
||||
echo [!] Missing environment variable: received JOB_BASE_NAME=[$JOB_BASE_NAME]
|
||||
job_status=1
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -405,6 +412,7 @@ tarball() {
|
|||
if [ $? -gt 0 ]
|
||||
then
|
||||
echo [!] Tarball creation failed with status [$status]
|
||||
job_status=1
|
||||
return 2
|
||||
fi
|
||||
|
||||
|
@ -415,7 +423,7 @@ tarball() {
|
|||
project=86Box
|
||||
cwd=$(pwd)
|
||||
first_build=1
|
||||
job_status=1
|
||||
job_status=0
|
||||
|
||||
# Parse arguments.
|
||||
single_build=0
|
||||
|
|
Loading…
Reference in a new issue