From e663b2ed12faf1857e10182cc0286de8d432f259 Mon Sep 17 00:00:00 2001 From: "sebastien.heurtematte" Date: Thu, 16 May 2024 09:36:35 +0200 Subject: [PATCH] refactor: agent definition per stage in buildImage function Signed-off-by: sebastien.heurtematte --- Jenkinsfile | 100 +++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 76 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6f43d88..f6ca6aa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,7 @@ pipeline { agent any options { + skipDefaultCheckout() buildDiscarder(logRotator(numToKeepStr: '5')) timeout(time: 90, unit: 'MINUTES') } @@ -19,16 +20,15 @@ pipeline { } stages { + stage('Checkout Workspace') { + steps { + checkout scm + stash(name: 'workspace', includes: '**') + } + } stage('Run Builds') { parallel { stage('nginx') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('nginx', 'stable-alpine', 'nginx/stable-alpine', [:], true) buildImage('nginx', 'stable-alpine-for-staging', 'nginx/stable-alpine-for-staging') @@ -36,38 +36,17 @@ pipeline { } stage('planet-venus') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('planet-venus', 'debian-10-slim', 'planet-venus', [:], true) } } stage('kubectl') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('kubectl', 'okd-c1', 'kubectl/okd-c1', [:], true) } } stage('hugo-node') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('hugo-node', 'h0.76.5-n12.22.1', 'hugo-node', ['HUGO_VERSION':'0.76.5', 'HUGO_FILENAME':'hugo_0.76.5_Linux-64bit.deb','NODE_VERSION': 'v12.22.1'], true) buildImage('hugo-node', 'h0.99.1-n16.15.0', 'hugo-node', ['HUGO_VERSION':'0.99.1', 'HUGO_FILENAME':'hugo_0.99.1_Linux-64bit.deb','NODE_VERSION': 'v16.15.0']) @@ -77,13 +56,6 @@ pipeline { } stage('drupal-node') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('drupal-node', 'd9.5.10-n18.18.2', 'drupal-node', ['DRUPAL_VERSION':'9.5.10', 'NODE_VERSION': 'v18.18.2'], true) buildImage('drupal-node', 'd10.2.2-n18.19.1', 'drupal-node', ['DRUPAL_VERSION':'10.2.2', 'NODE_VERSION': 'v18.19.1']) @@ -91,13 +63,6 @@ pipeline { } stage('stack-build-agent') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('stack-build-agent', 'h79.1-n12.22.1-jdk11', 'stack-build-agent/h79.1-n12.22.1-jdk11', [:], true) buildImage('stack-build-agent', 'h111.3-n18.19-jdk17', 'stack-build-agent', ['JDK_VERSION':'17']) @@ -107,13 +72,6 @@ pipeline { } stage('java-api-base') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('java-api-base', 'j11-openjdk', 'java-api-base', ['JDK_VERSION':'11:1.17'], true) buildImage('java-api-base', 'j17-openjdk', 'java-api-base', ['JDK_VERSION':'17:1.17']) @@ -121,26 +79,12 @@ pipeline { } stage('native-build-agent') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('native-build-agent', 'm23-n18.20.2', 'native-build-agent', [:], true) } } stage('containertools') { - agent { - kubernetes { - yaml loadOverridableResource( - libraryResource: 'org/eclipsefdn/container/agent.yml' - ) - } - } steps { buildImage('containertools', 'alpine-latest', 'containertools', [:], true) } @@ -169,18 +113,22 @@ def buildImage(String name, String version, String context, Map * Dockerfile ${context}/Dockerfile * Latest ${latest} """ - - container('containertools') { - containerBuild( - credentialsId: env.CREDENTIALS_ID, - name: env.NAMESPACE + '/' + name, - version: version, - dockerfile: context + '/Dockerfile', - context: context, - buildArgs: containerBuildArgs, - push: env.GIT_BRANCH == 'master', - latest: latest, - debug: false - ) + podTemplate(yaml: loadOverridableResource(libraryResource: 'org/eclipsefdn/container/agent.yml')) { + node(POD_LABEL) { + container('containertools') { + unstash('workspace') + containerBuild( + credentialsId: env.CREDENTIALS_ID, + name: env.NAMESPACE + '/' + name, + version: version, + dockerfile: context + '/Dockerfile', + context: context, + buildArgs: containerBuildArgs, + push: env.GIT_BRANCH == 'master', + latest: latest, + debug: false + ) + } + } } }