Skip to content

Commit

Permalink
add a mechanism to allow simulate LTS build on ci.jenkins.io by chang…
Browse files Browse the repository at this point in the history
…ing a value in a replay
  • Loading branch information
lemeurherve committed Jun 11, 2024
1 parent 93f18ea commit dbc09a3
Showing 1 changed file with 181 additions and 155 deletions.
336 changes: 181 additions & 155 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,91 @@ H 6,21 * * 3''')])

properties(listOfProperties)

// Set to "" in a replay to simulate a LTS build on ci.jenkins.io by setting the environment variables needed for a LTS
// Default value added as prefix to the env var names to prevent them to be taken in account when not simulating a LTS build
def SIMULATE_LTS_BUILD="DONT_"

stage('Build') {
def builds = [:]
def windowsImageTypes = [
'windowsservercore-ltsc2019',
]
for (anImageType in windowsImageTypes) {
def imageType = anImageType
builds[imageType] = {
nodeWithTimeout('windows-2019') {
stage('Checkout') {
checkout scm
}

withEnv(["IMAGE_TYPE=${imageType}"]) {
if (!infra.isTrusted()) {
/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
*/
stage("Build ${imageType}") {
infra.withDockerCredentials {
powershell './make.ps1'
}
// Define dummy env vars by default when not simulating a LTS build
withEnv ([
"${SIMULATE_LTS_BUILD}TAG_NAME=2.452.1",
"${SIMULATE_LTS_BUILD}JENKINS_VERSION=2.452.1",
"${SIMULATE_LTS_BUILD}JENKINS_SHA=d9ec867a35987b545c82ed0df5d2240ac208a8d06e065e9cdb869464f3b87a56",
"${SIMULATE_LTS_BUILD}PREVENT_PUBLICATION=true"
]) {
// Determine if the tag name (ie Jenkins version) correspond to a LTS (3 groups of digits)
// to use the appropriate bake target and set of images to build (including or not Java 11)
def isLTS
if (env.TAG_NAME && env.TAG_NAME =~ /^\d+\.\d+\.\d+$/) {
isLTS = true
target = 'linux-lts-with-jdk11'
} else {
isLTS = false
target = 'linux'
}
echo "= bake target: $target"
echo "= isLTS: $isLTS"

withEnv (["TARGET=${target}"]) {
def windowsImageTypes = [
'windowsservercore-ltsc2019',
]
for (anImageType in windowsImageTypes) {
def imageType = anImageType
builds[imageType] = {
nodeWithTimeout('windows-2019') {
stage('Checkout') {
checkout scm
}

stage("Test ${imageType}") {
infra.withDockerCredentials {
def windowsTestStatus = powershell(script: './make.ps1 test', returnStatus: true)
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
if (windowsTestStatus > 0) {
// If something bad happened let's clean up the docker images
error('Windows test stage failed.')
withEnv(["IMAGE_TYPE=${imageType}"]) {
if (!infra.isTrusted()) {
/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
*/
stage("Build ${imageType}") {
infra.withDockerCredentials {
powershell './make.ps1'
}
}
}
}

// disable until we get the parallel changes merged in
// def branchName = "${env.BRANCH_NAME}"
// if (branchName ==~ 'master'){
// stage('Publish Experimental') {
// infra.withDockerCredentials {
// withEnv(['DOCKERHUB_ORGANISATION=jenkins4eval','DOCKERHUB_REPO=jenkins']) {
// powershell './make.ps1 publish'
// }
// }
// }
// }
} else {
// Only publish when a tag triggered the build
if (env.TAG_NAME) {
// Split to ensure any suffix is not taken in account (but allow suffix tags to trigger rebuilds)
jenkins_version = env.TAG_NAME.split('-')[0]
withEnv(["JENKINS_VERSION=${jenkins_version}"]) {
stage('Publish') {
stage("Test ${imageType}") {
infra.withDockerCredentials {
withEnv(['DOCKERHUB_ORGANISATION=jenkins','DOCKERHUB_REPO=jenkins']) {
powershell './make.ps1 publish'
def windowsTestStatus = powershell(script: './make.ps1 test', returnStatus: true)
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
if (windowsTestStatus > 0) {
// If something bad happened let's clean up the docker images
error('Windows test stage failed.')
}
}
}

// disable until we get the parallel changes merged in
// def branchName = "${env.BRANCH_NAME}"
// if (branchName ==~ 'master'){
// stage('Publish Experimental') {
// infra.withDockerCredentials {
// withEnv(['DOCKERHUB_ORGANISATION=jenkins4eval','DOCKERHUB_REPO=jenkins']) {
// powershell './make.ps1 publish'
// }
// }
// }
// }
} else {
// Only publish when a tag triggered the build & the publication isn't prevented
// Can be prevented when simulating a LTS build by setting SIMULATE_LTS_BUILD to ""
if (env.TAG_NAME && (env.DONT_PREVENT_PUBLICATION == "true")) {
// Split to ensure any suffix is not taken in account (but allow suffix tags to trigger rebuilds)
jenkins_version = env.TAG_NAME.split('-')[0]
withEnv(["JENKINS_VERSION=${jenkins_version}"]) {
stage('Publish') {
infra.withDockerCredentials {
withEnv(['DOCKERHUB_ORGANISATION=jenkins','DOCKERHUB_REPO=jenkins']) {
powershell './make.ps1 publish'
}
}
}
}
}
Expand All @@ -75,139 +104,136 @@ stage('Build') {
}
}
}
}
}

if (!infra.isTrusted()) {
def images
def target

def imagesWithoutJava11 = [
'alpine_jdk17',
'alpine_jdk21',
'debian_jdk17',
'debian_jdk21',
'debian_slim_jdk17',
'debian_slim_jdk21',
'rhel_ubi9_jdk17',
'rhel_ubi9_jdk21',
]
def imagesWithJava11 = [
'almalinux_jdk11',
'alpine_jdk11',
'alpine_jdk17',
'alpine_jdk21',
'debian_jdk11',
'debian_jdk17',
'debian_jdk21',
'debian_slim_jdk11',
'debian_slim_jdk17',
'debian_slim_jdk21',
'rhel_ubi8_jdk11',
'rhel_ubi9_jdk17',
'rhel_ubi9_jdk21',
]
// Build all images including Java 11 if the version match a LTS versioning pattern
// TODO: remove when Java 11 is removed from LTS line
// See https://github.com/jenkinsci/docker/issues/1890
if (env.TAG_NAME && env.TAG_NAME =~ /^\d+\.\d+\.\d+$/) {
images = imagesWithJava11
target = 'linux-lts-with-jdk11'
} else {
images = imagesWithoutJava11
target = 'linux'
}
for (i in images) {
def imageToBuild = i

builds[imageToBuild] = {
nodeWithTimeout('docker') {
deleteDir()

stage('Checkout') {
checkout scm
}

stage('Static analysis') {
sh 'make hadolint shellcheck'
}
if (!infra.isTrusted()) {
def images

def imagesWithoutJava11 = [
'alpine_jdk17',
'alpine_jdk21',
'debian_jdk17',
'debian_jdk21',
'debian_slim_jdk17',
'debian_slim_jdk21',
'rhel_ubi9_jdk17',
'rhel_ubi9_jdk21',
]
def imagesWithJava11 = [
'almalinux_jdk11',
'alpine_jdk11',
'alpine_jdk17',
'alpine_jdk21',
'debian_jdk11',
'debian_jdk17',
'debian_jdk21',
'debian_slim_jdk11',
'debian_slim_jdk17',
'debian_slim_jdk21',
'rhel_ubi8_jdk11',
'rhel_ubi9_jdk17',
'rhel_ubi9_jdk21',
]
if (isLTS) {
images = imagesWithJava11
} else {
images = imagesWithoutJava11
}
// Build all images including Java 11 if the version match a LTS versioning pattern
// TODO: remove when Java 11 is removed from LTS line
// See https://github.com/jenkinsci/docker/issues/1890
for (i in images) {
def imageToBuild = i

builds[imageToBuild] = {
nodeWithTimeout('docker') {
deleteDir()

stage('Checkout') {
checkout scm
}

/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
*/
stage("Build linux-${imageToBuild}") {
infra.withDockerCredentials {
sh "make build-${imageToBuild}"
}
}
stage('Static analysis') {
sh 'make hadolint shellcheck'
}

stage("Test linux-${imageToBuild}") {
sh "make prepare-test"
try {
infra.withDockerCredentials {
sh "make test-${imageToBuild}"
/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
*/
stage("Build linux-${imageToBuild}") {
infra.withDockerCredentials {
sh "make build-${imageToBuild}"
}
}
} catch (err) {
error("${err.toString()}")
} finally {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/*.xml')
}
}
}
}
}
builds['multiarch-build'] = {
nodeWithTimeout('docker') {
stage('Checkout') {
deleteDir()
checkout scm
}

// sanity check that proves all images build on declared platforms
stage('Multi arch build') {
infra.withDockerCredentials {
withEnv(["TARGET=${target}"]){
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx bake --file docker-bake.hcl "${TARGET}"
'''
stage("Test linux-${imageToBuild}") {
sh "make prepare-test"
try {
infra.withDockerCredentials {
sh "make test-${imageToBuild}"
}
} catch (err) {
error("${err.toString()}")
} finally {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/*.xml')
}
}
}
}
}
}
}
} else {
// Only publish when a tag triggered the build
if (env.TAG_NAME) {
// Split to ensure any suffix is not taken in account (but allow suffix tags to trigger rebuilds)
jenkins_version = env.TAG_NAME.split('-')[0]
builds['linux'] = {
withEnv(["JENKINS_VERSION=${jenkins_version}"]) {
builds['multiarch-build'] = {
nodeWithTimeout('docker') {
stage('Checkout') {
deleteDir()
checkout scm
}

stage('Publish') {
// sanity check that proves all images build on declared platforms
stage('Multi arch build') {
infra.withDockerCredentials {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
make publish
'''
docker buildx bake --file docker-bake.hcl "${TARGET}"
'''
}
}
}
}
} else {
// Only publish when a tag triggered the build
if (env.TAG_NAME) {
// Split to ensure any suffix is not taken in account (but allow suffix tags to trigger rebuilds)
jenkins_version = env.TAG_NAME.split('-')[0]
builds['linux'] = {
withEnv(["JENKINS_VERSION=${jenkins_version}"]) {
nodeWithTimeout('docker') {
stage('Checkout') {
checkout scm
}

stage('Publish') {
// Publication isn't prevented by default, only if simulating an LTS
if (env.DONT_PREVENT_PUBLICATION == "true") {
infra.withDockerCredentials {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
make publish
'''
}
}
}
}
}
}
}
}

parallel builds
}
}

parallel builds
}


void nodeWithTimeout(String label, def body) {
node(label) {
timeout(time: 60, unit: 'MINUTES') {
Expand Down

0 comments on commit dbc09a3

Please sign in to comment.