Skip to content

Commit

Permalink
Perform Jenkins builds in /dash-src all the time to fix caching issues (
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock authored and UdjinM6 committed Aug 29, 2018
1 parent 40eee17 commit 799e3c3
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,9 @@ for(int i = 0; i < targets.size(); i++) {
def UID = sh(returnStdout: true, script: 'id -u').trim()
def HOME = sh(returnStdout: true, script: 'echo $HOME').trim()
def pwd = sh(returnStdout: true, script: 'pwd').trim()
def hasCache = false

checkout scm

// restore cache
try {
copyArtifacts(projectName: "dashpay-dash/${BRANCH_NAME}", optional: true, selector: lastSuccessful(), filter: "ci-cache-${target}.tar.gz")
} catch (Exception e) {
}
if (fileExists("ci-cache-${target}.tar.gz")) {
hasCache = true
echo "Using cache from dashpay-dash/${BRANCH_NAME}"
} else {
try {
copyArtifacts(projectName: 'dashpay-dash/develop', optional: true, selector: lastSuccessful(), filter: "ci-cache-${target}.tar.gz");
} catch (Exception e) {
}
if (fileExists("ci-cache-${target}.tar.gz")) {
hasCache = true
echo "Using cache from dashpay-dash/develop"
}
}

def env = [
"BUILD_TARGET=${target}",
"PULL_REQUEST=false",
Expand All @@ -61,29 +41,55 @@ for(int i = 0; i < targets.size(); i++) {
builderImage = docker.build("${builderImageName}", "--build-arg BUILD_TARGET=${target} ci -f ci/Dockerfile.builder")
}

if (hasCache) {
sh "cd ${pwd} && tar xzfv ci-cache-${target}.tar.gz"
} else {
sh "mkdir -p ${pwd}/ci-cache-${target}"
}

builderImage.inside("-t") {
// copy source into fixed path
// we must build under the same path everytime as otherwise caches won't work properly
sh "cp -ra ${pwd}/. /dash-src/"

// restore cache
def hasCache = false
try {
copyArtifacts(projectName: "dashpay-dash/${BRANCH_NAME}", optional: true, selector: lastSuccessful(), filter: "ci-cache-${target}.tar.gz")
} catch (Exception e) {
}
if (fileExists("ci-cache-${target}.tar.gz")) {
hasCache = true
echo "Using cache from dashpay-dash/${BRANCH_NAME}"
} else {
try {
copyArtifacts(projectName: 'dashpay-dash/develop', optional: true, selector: lastSuccessful(), filter: "ci-cache-${target}.tar.gz");
} catch (Exception e) {
}
if (fileExists("ci-cache-${target}.tar.gz")) {
hasCache = true
echo "Using cache from dashpay-dash/develop"
}
}

if (hasCache) {
sh "cd /dash-src && tar xzf ${pwd}/ci-cache-${target}.tar.gz"
} else {
sh "mkdir -p /dash-src/ci-cache-${target}"
}

stage("${target}/depends") {
sh './ci/build_depends.sh'
sh 'cd /dash-src && ./ci/build_depends.sh'
}
stage("${target}/build") {
sh './ci/build_src.sh'
sh 'cd /dash-src && ./ci/build_src.sh'
}
stage("${target}/test") {
sh './ci/test_unittests.sh'
sh 'cd /dash-src && ./ci/test_unittests.sh'
}
stage("${target}/test") {
sh './ci/test_integrationtests.sh'
sh 'cd /dash-src && ./ci/test_integrationtests.sh'
}

// archive cache and copy it into the jenkins workspace
sh "cd /dash-src && tar czfv ci-cache-${target}.tar.gz ci-cache-${target} && cp ci-cache-${target}.tar.gz ${pwd}/"
}

// archive cache
sh "tar czfv ci-cache-${target}.tar.gz ci-cache-${target}"
// upload cache
archiveArtifacts artifacts: "ci-cache-${target}.tar.gz", fingerprint: true
}
}
Expand Down

0 comments on commit 799e3c3

Please sign in to comment.