1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-11-24 08:32:32 +02:00

Build piper binary in Consumer Tests (#1240)

This commit is contained in:
Florian Wilhelm 2020-03-04 13:27:27 +01:00 committed by GitHub
parent 2b2b57305e
commit 15ef9adaaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 19 deletions

View File

@ -64,6 +64,8 @@ class TestRunnerThread extends Thread {
"-e CASC_JENKINS_CONFIG=/workspace/jenkins.yml " +
"-e ${testCaseConfig.deployCredentialEnv.username} " +
"-e ${testCaseConfig.deployCredentialEnv.password} " +
"-e LIBRARY_VERSION_UNDER_TEST=${libraryVersionUnderTest} " +
"-e REPOSITORY_UNDER_TEST=${repositoryUnderTest} " +
"-e BRANCH_NAME=${testCaseConfig.referenceAppRepo.branch} ppiper/jenkinsfile-runner")
println "*****[INFO] Test case '${uniqueName}' finished successfully.*****"

View File

@ -19,30 +19,46 @@ class PiperGoUtils implements Serializable {
if (utils.unstash('piper-bin').size() > 0) return
def libraries = getLibrariesInfo()
String version
libraries.each {lib ->
if (lib.name == 'piper-lib-os') {
version = lib.version
if (steps.env.REPOSITORY_UNDER_TEST && steps.env.LIBRARY_VERSION_UNDER_TEST) {
steps.echo("Running in a consumer test, building unit-under-test binary for verification.")
steps.dockerExecute(script: steps, dockerImage: 'golang:1.13', dockerOptions: '-u 0', dockerEnvVars: [
REPOSITORY_UNDER_TEST: steps.env.REPOSITORY_UNDER_TEST,
LIBRARY_VERSION_UNDER_TEST: steps.env.LIBRARY_VERSION_UNDER_TEST
]) {
steps.sh 'wget https://github.com/$REPOSITORY_UNDER_TEST/archive/$LIBRARY_VERSION_UNDER_TEST.tar.gz'
steps.sh 'tar xzf $LIBRARY_VERSION_UNDER_TEST.tar.gz'
steps.dir("jenkins-library-${steps.env.LIBRARY_VERSION_UNDER_TEST}") {
steps.sh 'CGO_ENABLED=0 go build -tags release -o ../piper . && chmod +x ../piper && chown 1000:999 ../piper'
}
steps.sh 'rm -rf $LIBRARY_VERSION_UNDER_TEST.tar.gz jenkins-library-$LIBRARY_VERSION_UNDER_TEST'
}
}
def fallbackUrl = 'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master'
def piperBinUrl = (version == 'master') ? fallbackUrl : "https://github.com/SAP/jenkins-library/releases/download/${version}/piper"
boolean downloaded = downloadGoBinary(piperBinUrl)
if (!downloaded) {
//Inform that no Piper binary is available for used library branch
steps.echo ("Not able to download go binary of Piper for version ${version}")
//Fallback to master version & throw error in case this fails
steps.retry(5) {
if (!downloadGoBinary(fallbackUrl)) {
steps.sleep(2)
steps.error("Download of Piper go binary failed.")
} else {
def libraries = getLibrariesInfo()
String version
libraries.each {lib ->
if (lib.name == 'piper-lib-os') {
version = lib.version
}
}
def fallbackUrl = 'https://github.com/SAP/jenkins-library/releases/latest/download/piper_master'
def piperBinUrl = (version == 'master') ? fallbackUrl : "https://github.com/SAP/jenkins-library/releases/download/${version}/piper"
boolean downloaded = downloadGoBinary(piperBinUrl)
if (!downloaded) {
//Inform that no Piper binary is available for used library branch
steps.echo ("Not able to download go binary of Piper for version ${version}")
//Fallback to master version & throw error in case this fails
steps.retry(5) {
if (!downloadGoBinary(fallbackUrl)) {
steps.sleep(2)
steps.error("Download of Piper go binary failed.")
}
}
}
}
utils.stashWithMessage('piper-bin', 'failed to stash piper binary', 'piper')
}