Skip to content
Permalink
Browse files
Add staging stage to Jenkinsfile
This enables branches other than main to publish their changes to the
staging branch automatically
  • Loading branch information
rvesse committed Jun 21, 2021
1 parent 6dadaeb commit 45e8284ed0c0dd82cc4088beb89e9260180dd334
Showing 1 changed file with 33 additions and 0 deletions.
@@ -25,6 +25,7 @@ pipeline {
environment {
HUGO_VERSION = '0.66.0'
DEPLOY_BRANCH = 'asf-site'
STAGING_BRANCH = 'staging'
}

stages {
@@ -61,6 +62,38 @@ pipeline {
}
}
}
stage('Staging') {
when {
not {
branch 'main'
}
}
steps {
// Checkout branch with generated content
sh """
git checkout ${STAGING_BRANCH}
git pull origin ${STAGING_BRANCH}
"""

// Remove the content of the target branch and replace it with the content of the temp folder
sh """
rm -rf ${WORKSPACE}/content
git rm -r --cached content/*
mkdir -p ${WORKSPACE}/content
cp -rT ${env.TMP_DIR}/* ${WORKSPACE}/content
"""

// Commit the changes to the target branch
env.COMMIT_MESSAGE = "Staged site from ${BRANCH_NAME} (${env.LAST_SHA})"
sh """
git add -A
git commit -m "${env.COMMIT_MESSAGE}" | true
"""

// Push the generated content for deployment
sh "git push -u origin ${STAGING_BRANCH}"
}
}
stage('Deploy') {
when {
anyOf {

0 comments on commit 45e8284

Please sign in to comment.