Example Jenkinsfile for two stage deploy of a hugo website.
Triggers on a webhook from github, which triggers the build.
properties([pipelineTriggers([githubPush()])])
pipeline {
agent any
stages {
/* checkout repo */
stage('Checkout SCM') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'master']],
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]],
userRemoteConfigs: [[
url: 'https://github.com/user/repo-url.git',
credentialsId: '',
]]
])
}
}
stage('Build Beta') {
steps {
echo ">> Build application"
sh "hugo -b https://beta.base.url"
}
}
stage('Deploy Beta') {
steps {
sshagent(["linode"]) {
sh 'rsync -r -e "ssh -o StrictHostKeyChecking=no" "$WORKSPACE/public/" user@host.tld:/path/to/site/public_html'
}
}
}
stage('Test before deploying live') {
steps {
input message: 'Do you want to release this build?',
parameters: [[$class: 'BooleanParameterDefinition',
defaultValue: false,
description: 'Ticking this box will deploy to hellracers.se',
name: 'Release']]
}
}
stage('Build Live') {
steps {
echo ">> Build application"
sh "hugo -b https://base.url"
}
}
stage('Deploy Live') {
steps {
sshagent(["linode"]) {
sh 'rsync -r -e "ssh -o StrictHostKeyChecking=no" "$WORKSPACE/public/" user@host.tld:/path/to/site/public_html'
}
}
}
}
/* Cleanup workspace */
post {
always {
deleteDir()
}
}
}