2021-10-26 14:33:46 +00:00
|
|
|
pipeline {
|
|
|
|
agent {
|
2023-04-03 15:28:16 +00:00
|
|
|
label 'linux && x86_64'
|
2021-10-26 14:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parameters {
|
|
|
|
string(
|
2023-04-18 16:26:43 +00:00
|
|
|
name: 'GIT_REF',
|
2021-10-26 14:33:46 +00:00
|
|
|
defaultValue: 'master',
|
2023-04-18 16:26:43 +00:00
|
|
|
description: 'Branch, tag, or commit to build.'
|
2021-10-26 14:33:46 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'IMAGE_NAME',
|
|
|
|
defaultValue: 'statusteam/go-waku',
|
|
|
|
description: 'Docker image name.',
|
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'IMAGE_TAG',
|
2023-04-18 16:26:43 +00:00
|
|
|
defaultValue: env.JOB_BASE_NAME == 'release' ? 'stable' : 'deploy-test',
|
|
|
|
description: 'Docker image tag.',
|
2021-10-26 14:33:46 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
options {
|
|
|
|
timestamps()
|
|
|
|
buildDiscarder(logRotator(
|
|
|
|
numToKeepStr: '10',
|
|
|
|
daysToKeepStr: '30',
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
|
|
stage('Build') {
|
|
|
|
steps { script {
|
2023-04-18 16:26:43 +00:00
|
|
|
def imageTag = GIT_COMMIT.take(8)
|
|
|
|
if (env.JOB_BASE_NAME == 'release') {
|
|
|
|
imageTag = params.GIT_REF
|
|
|
|
}
|
2021-10-26 14:33:46 +00:00
|
|
|
image = docker.build(
|
2023-04-18 16:26:43 +00:00
|
|
|
"${params.IMAGE_NAME}:${imageTag}",
|
2021-10-26 14:33:46 +00:00
|
|
|
"--build-arg='GIT_COMMIT=${GIT_COMMIT.take(8)}' ."
|
|
|
|
)
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Push') {
|
|
|
|
steps { script {
|
|
|
|
withDockerRegistry([
|
|
|
|
credentialsId: "dockerhub-statusteam-auto", url: ""
|
|
|
|
]) {
|
|
|
|
image.push()
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Deploy') {
|
|
|
|
steps { script {
|
|
|
|
withDockerRegistry([
|
|
|
|
credentialsId: "dockerhub-statusteam-auto", url: ""
|
|
|
|
]) {
|
|
|
|
image.push(env.IMAGE_TAG)
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post {
|
2022-09-27 14:08:56 +00:00
|
|
|
success { script {
|
2022-10-12 13:31:11 +00:00
|
|
|
discordNotify(
|
2023-04-18 16:26:43 +00:00
|
|
|
header: 'Go-Waku build successful!',
|
2022-10-12 13:31:11 +00:00
|
|
|
cred: 'discord-waku-deployments-webhook',
|
|
|
|
)
|
2022-09-27 14:08:56 +00:00
|
|
|
} }
|
2021-10-26 14:33:46 +00:00
|
|
|
always { cleanWs() }
|
|
|
|
}
|
|
|
|
}
|
2022-10-12 13:31:11 +00:00
|
|
|
|
|
|
|
def discordNotify(Map args=[:]) {
|
|
|
|
def opts = [
|
|
|
|
header: args.header ?: 'Deployment successful!',
|
|
|
|
cred: args.cred ?: null,
|
|
|
|
]
|
|
|
|
def repo = [
|
|
|
|
url: GIT_URL.minus('.git'),
|
|
|
|
branch: GIT_BRANCH.minus('origin/'),
|
|
|
|
commit: GIT_COMMIT.take(8),
|
|
|
|
prev: (
|
|
|
|
env.GIT_PREVIOUS_SUCCESSFUL_COMMIT ?: env.GIT_PREVIOUS_COMMIT ?: 'master'
|
|
|
|
).take(8),
|
|
|
|
]
|
|
|
|
wrap([$class: 'BuildUser']) {
|
|
|
|
BUILD_USER_ID = env.BUILD_USER_ID
|
|
|
|
}
|
|
|
|
withCredentials([
|
|
|
|
string(
|
|
|
|
credentialsId: opts.cred,
|
|
|
|
variable: 'DISCORD_WEBHOOK',
|
|
|
|
),
|
|
|
|
]) {
|
|
|
|
discordSend(
|
|
|
|
link: env.BUILD_URL,
|
|
|
|
result: currentBuild.currentResult,
|
|
|
|
webhookURL: env.DISCORD_WEBHOOK,
|
|
|
|
title: "${env.JOB_NAME}#${env.BUILD_NUMBER}",
|
|
|
|
description: """
|
|
|
|
${opts.header}
|
|
|
|
Image: [`${IMAGE_NAME}:${IMAGE_TAG}`](https://hub.docker.com/r/${IMAGE_NAME}/tags?name=${IMAGE_TAG})
|
|
|
|
Branch: [`${repo.branch}`](${repo.url}/commits/${repo.branch})
|
|
|
|
Commit: [`${repo.commit}`](${repo.url}/commit/${repo.commit})
|
|
|
|
Diff: [`${repo.prev}...${repo.commit}`](${repo.url}/compare/${repo.prev}...${repo.commit})
|
|
|
|
By: [`${BUILD_USER_ID}`](${repo.url}/commits?author=${BUILD_USER_ID})
|
|
|
|
""",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|