From edf35e444b1723d54d4d26bc2e54b05bfe84c9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Sun, 23 Jun 2024 22:05:44 +0200 Subject: [PATCH 1/2] feat: dedicated previews pipeline --- Jenkinsfile | 24 ------------------- Jenkinsfile_previews | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 Jenkinsfile_previews diff --git a/Jenkinsfile b/Jenkinsfile index 719d95f..847f2e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -47,30 +47,6 @@ pipeline { } } - stage('Deploy PR to preview site') { - when { - allOf{ - changeRequest target: 'main' - // Only deploy from infra.ci.jenkins.io - expression { infra.isInfra() } - } - } - environment { - NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token') - } - steps { - sh 'netlify-deploy --draft=true --siteName "stats-jenkins-io" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./dist' - } - post { - success { - recordDeployment('jenkins-infra', 'stats.jenkins.io', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--stats-jenkins-io.netlify.app") - } - failure { - recordDeployment('jenkins-infra', 'stats.jenkins.io', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--stats-jenkins-io.netlify.app") - } - } - } - stage('Deploy to production') { when { allOf{ diff --git a/Jenkinsfile_previews b/Jenkinsfile_previews new file mode 100644 index 0000000..462c4ff --- /dev/null +++ b/Jenkinsfile_previews @@ -0,0 +1,55 @@ +pipeline { + options { + timeout(time: 60, unit: 'MINUTES') + ansiColor('xterm') + disableConcurrentBuilds(abortPrevious: true) + buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '5', numToKeepStr: '5') + } + + agent { + label 'linux-arm64-docker || arm64linux' + } + + stages { + stage('Install dependencies') { + steps { + sh ''' + asdf install + npm install + ''' + } + } + + stage('Build') { + steps { + sh ''' + npm run build + ''' + } + } + + stage('Deploy PR to preview site') { + when { + allOf{ + changeRequest target: 'main' + // Only deploy from infra.ci.jenkins.io + expression { infra.isInfra() } + } + } + environment { + NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token') + } + steps { + sh 'netlify-deploy --draft=true --siteName "stats-jenkins-io" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./dist' + } + post { + success { + recordDeployment('jenkins-infra', 'stats.jenkins.io', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--stats-jenkins-io.netlify.app") + } + failure { + recordDeployment('jenkins-infra', 'stats.jenkins.io', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--stats-jenkins-io.netlify.app") + } + } + } + } +} From 1743479487efa3fc36a7459040f9ce55a463486f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= Date: Sun, 23 Jun 2024 22:43:31 +0200 Subject: [PATCH 2/2] don't run any stage outside of infra.ci.jenkins.io and pull requests --- Jenkinsfile_previews | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Jenkinsfile_previews b/Jenkinsfile_previews index 462c4ff..9ee1783 100644 --- a/Jenkinsfile_previews +++ b/Jenkinsfile_previews @@ -12,6 +12,13 @@ pipeline { stages { stage('Install dependencies') { + when { + allOf{ + changeRequest target: 'main' + // Only deploy from infra.ci.jenkins.io + expression { infra.isInfra() } + } + } steps { sh ''' asdf install @@ -21,6 +28,13 @@ pipeline { } stage('Build') { + when { + allOf{ + changeRequest target: 'main' + // Only deploy from infra.ci.jenkins.io + expression { infra.isInfra() } + } + } steps { sh ''' npm run build