Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (123 sloc) 3.66 KB
library 'cb-days@master'
def hugoPodYaml = libraryResource 'podtemplates/hugo/pod.yml'
def cloudRunYaml = libraryResource 'podtemplates/cloud-run.yml'
def prNumber
pipeline {
agent none
options {
buildDiscarder(logRotator(numToKeepStr: '2'))
skipDefaultCheckout true
preserveStashes(buildCount: 2)
}
triggers {
eventTrigger jmespathQuery("action=='closed' && repository.full_name=='${repoOwner}/${repo}'")
}
environment {
repoOwner = "${repoOwner}"
repo = "${repo}"
credId = "${githubCredentialId}"
}
stages {
stage('Preview environment') {
agent {
kubernetes {
label 'hugo-builder'
yaml hugoPodYaml
}
}
when {
beforeAgent true
allOf {
not { triggeredBy 'EventTriggerCause' }
branch 'pr-*'
}
}
stages {
stage("Build site") {
steps {
checkout scm
container('hugo') {
sh "hugo"
stash name: "public", includes: "public/**"
}
}
}
stage("Build and push image") {
steps {
containerBuildPushGeneric("${projectName}", "${BRANCH_NAME.toLowerCase()}", "${gcpProject}"){
checkout scm
unstash "public"
}
}
}
stage("Deploy to preview env") {
steps {
cloudRunDeploy(serviceName: "${projectName}-${BRANCH_NAME.toLowerCase()}", image: "gcr.io/${gcpProject}/${projectName}:${BRANCH_NAME.toLowerCase()}", deployType: "${deployTypePR}", region: "${gcpRegionPR}", clusterName: "${clusterNamePR}", namespace: "${namespacePR}")
}
}
}
}
stage('Master build & deploy') {
agent {
kubernetes {
label 'hugo-builder'
yaml hugoPodYaml
}
}
when {
beforeAgent true
allOf {
not { triggeredBy 'EventTriggerCause' }
branch 'master'
}
}
stages {
stage("Build site") {
steps {
checkout scm
container('hugo') {
sh "hugo"
stash name: "public", includes: "public/**"
}
}
}
stage("Build and push image") {
steps {
containerBuildPushGeneric("${projectName}", "master-${env.BUILD_NUMBER}", "${gcpProject}"){
checkout scm
unstash "public"
}
}
}
stage("Deploy to preview env") {
steps {
cloudRunDeploy(serviceName: "${projectName}", image: "gcr.io/${gcpProject}/${projectName}:master-${env.BUILD_NUMBER}", deployType: "${deployTypeMaster}", region: "${gcpRegionMaster}", clusterName: "${clusterNameMaster}", namespace: "${namespaceMaster}")
}
}
}
}
stage('PR Delete') {
agent {
kubernetes {
label 'default-jnlp'
}
}
when {
beforeAgent true
allOf {
branch 'master'
triggeredBy 'EventTriggerCause'
}
}
steps {
withCredentials([usernamePassword(credentialsId: 'cli-username-token', usernameVariable: 'JENKINS_CLI_USR', passwordVariable: 'JENKINS_CLI_PSW')]) {
script {
prNumber = sh (script: "curl -u $JENKINS_CLI_USR:$JENKINS_CLI_PSW --silent ${BUILD_URL}api/json | jq -r '.actions[0].causes[0].event.number' | tr -d '\n'",
returnStdout: true)
}
}
cloudRunDelete(serviceName: "${projectName}-pr-${prNumber}", deployType: "${deployTypePR}", region: "${gcpRegionPR}", clusterName: "${clusterNamePR}", namespace: "${namespacePR}")
}
}
}
}
You can’t perform that action at this time.