From 0a84f48e438a72046de148103016f375c179f463 Mon Sep 17 00:00:00 2001 From: Dylan Simon Date: Thu, 22 Feb 2018 14:16:45 -0500 Subject: [PATCH] [jenkins] Build PRs against upstream target branch cleanup unused image tags; may want to switch away from Dockerfile to an explicit container run at some point. --- Jenkinsfile | 99 ++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f3791c8d..6ea10bd9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ -def triqsProject = '/TRIQS/triqs/' + env.BRANCH_NAME.replaceAll('/', '%2F') +def triqsBranch = env.CHANGE_TARGET ?: env.BRANCH_NAME +def triqsProject = '/TRIQS/triqs/' + triqsBranch.replaceAll('/', '%2F') properties([ disableConcurrentBuilds(), @@ -16,22 +17,22 @@ def platforms = [:] def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc", "centos-gcc"] for (int i = 0; i < dockerPlatforms.size(); i++) { def platform = dockerPlatforms[i] - platforms[platform] = { -> - stage(platform) { - timeout(time: 1, unit: 'HOURS') { - node('docker') { - checkout scm - /* construct a Dockerfile for this base */ - sh ''' - ( echo "FROM flatironinstitute/triqs:$BRANCH_NAME-$STAGE_NAME" ; sed '0,/^FROM /d' Dockerfile ) > Dockerfile.jenkins - mv -f Dockerfile.jenkins Dockerfile - ''' - /* build and tag */ - def img = docker.build("flatironinstitute/dft_tools:${env.BRANCH_NAME}-${env.STAGE_NAME}") - } + platforms[platform] = { -> stage(platform) { + timeout(time: 1, unit: 'HOURS') { + node('docker') { + checkout scm + /* construct a Dockerfile for this base */ + sh """ + ( echo "FROM flatironinstitute/triqs:${triqsBranch}-${env.STAGE_NAME}" ; sed '0,/^FROM /d' Dockerfile ) > Dockerfile.jenkins + mv -f Dockerfile.jenkins Dockerfile + """ + /* build and tag */ + def img = docker.build("flatironinstitute/dft_tools:${env.BRANCH_NAME}-${env.STAGE_NAME}") + /* but we don't need the tag so clean it up (alternatively, could refacter to run in container) */ + sh "docker rmi ${img.imageName()}" } } - } + } } } def osxPlatforms = [ @@ -41,47 +42,45 @@ def osxPlatforms = [ for (int i = 0; i < osxPlatforms.size(); i++) { def platformEnv = osxPlatforms[i] def platform = platformEnv[0] - platforms["osx-$platform"] = { -> - stage("osx-$platform") { - timeout(time: 1, unit: 'HOURS') { - node('osx && triqs') { - def workDir = pwd() - def tmpDir = pwd(tmp:true) - def buildDir = "$tmpDir/build" - def installDir = "$tmpDir/install" + platforms["osx-$platform"] = { -> stage("osx-$platform") { + timeout(time: 1, unit: 'HOURS') { + node('osx && triqs') { + def srcDir = pwd() + def tmpDir = pwd(tmp:true) + def buildDir = "$tmpDir/build" + def installDir = "$tmpDir/install" - dir(installDir) { - deleteDir() - } + dir(installDir) { + deleteDir() + } - copyArtifacts(projectName: triqsProject, selector: upstream(fallbackToLastSuccessful: true), filter: "osx-${platform}.zip") - unzip(zipFile: "osx-${platform}.zip", dir: installDir) - /* fixup zip-stripped permissions (JENKINS-13128) */ - sh "chmod +x $installDir/bin/*" + copyArtifacts(projectName: triqsProject, selector: upstream(fallbackToLastSuccessful: true), filter: "osx-${platform}.zip") + unzip(zipFile: "osx-${platform}.zip", dir: installDir) + /* fixup zip-stripped permissions (JENKINS-13128) */ + sh "chmod +x $installDir/bin/*" - checkout scm + checkout scm - dir(buildDir) { withEnv(platformEnv[1]+[ - "PATH=$installDir/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin", - "CPATH=$installDir/include", - "LIBRARY_PATH=$installDir/lib", - "CMAKE_PREFIX_PATH=$installDir/share/cmake"]) { - deleteDir() - sh "cmake $workDir -DTRIQS_ROOT=$installDir" - sh "make -j2" - try { - sh "make test" - } catch (exc) { - archiveArtifacts(artifacts: 'Testing/Temporary/LastTest.log') - throw exc - } - sh "make install" - } } - // zip(zipFile: "osx-${platform}.zip", archive: true, dir: installDir) - } + dir(buildDir) { withEnv(platformEnv[1]+[ + "PATH=$installDir/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin", + "CPATH=$installDir/include", + "LIBRARY_PATH=$installDir/lib", + "CMAKE_PREFIX_PATH=$installDir/share/cmake"]) { + deleteDir() + sh "cmake $srcDir -DTRIQS_ROOT=$installDir" + sh "make -j2" + try { + sh "make test" + } catch (exc) { + archiveArtifacts(artifacts: 'Testing/Temporary/LastTest.log') + throw exc + } + sh "make install" + } } + // zip(zipFile: "osx-${platform}.zip", archive: true, dir: installDir) } } - } + } } } parallel platforms