-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrelease.Jenkinsfile
88 lines (79 loc) · 3.72 KB
/
release.Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pipeline {
agent any
tools {
go 'Go 1.18'
}
environment {
RELEASE_TYPE = 'release'
GIT_CREDENTIAL_ID = 'wf-jenkins-github'
GITHUB_TOKEN = credentials('GITHUB_TOKEN')
REPO_NAME = 'wavefront-kubernetes-adapter'
}
parameters {
string(name: 'VERSION_NUMBER', defaultValue: '', description: 'The version number to release as')
string(name: 'TARGET_COMMITISH', defaultValue: 'master', description: 'Specify a specific commit hash or branch to release the version to.')
string(name: 'RELEASE_NOTES', defaultValue: '', description: 'The public release notes for the version. Use \\n to create newlines')
booleanParam(name: 'IS_DRAFT', defaultValue: true, description: 'If the release should be marked as a draft (unpublished)')
booleanParam(name: 'IS_PRERELEASE', defaultValue: false, description: 'If the release should be marked as a prerelease')
booleanParam(name: 'createGithubRelease', defaultValue: true, description: 'Mark as false if you only want to build/push docker images. Note: a tag specified by the name VERSION must be created in the repo already for this option to be turned off')
}
stages {
stage("Publish GA Harbor Image") {
environment {
HARBOR_CREDS = credentials("projects-registry-vmware-tanzu_observability-robot")
DOCKER_REPO = 'projects.registry.vmware.com/tanzu_observability'
DOCKER_IMAGE = 'kubernetes-hpa-adapter'
VERSION = "${params.VERSION_NUMBER}"
}
steps {
sh 'echo $HARBOR_CREDS_PSW | docker login $DOCKER_REPO -u $HARBOR_CREDS_USR --password-stdin'
sh './scripts/install_docker_buildx.sh'
sh 'make publish'
}
}
stage("Publish GA Docker Hub") {
environment {
DOCKERHUB_CREDS=credentials('Dockerhub_svcwfjenkins')
DOCKER_REPO = 'wavefronthq'
DOCKER_IMAGE = 'wavefront-hpa-adapter'
VERSION = "${params.VERSION_NUMBER}"
}
steps {
sh 'echo $DOCKERHUB_CREDS_PSW | docker login -u $DOCKERHUB_CREDS_USR --password-stdin'
sh './scripts/install_docker_buildx.sh'
sh 'make publish'
}
}
stage('Create Github Release') {
steps {
script {
if (params.createGithubRelease) {
TARGET_COMMITISH_TRIMMED = TARGET_COMMITISH.minus("origin/")
sh "curl -XPOST -H \"Authorization: token ${GITHUB_TOKEN}\" -H \"Accept: application/vnd.github.v3+json\" https://api.github.com/repos/wavefrontHQ/${REPO_NAME}/releases -d \'{\"tag_name\": \"${VERSION_NUMBER}\", \"target_commitish\": \"${TARGET_COMMITISH_TRIMMED}\", \"name\": \"Release v${VERSION_NUMBER}\", \"body\": \"${RELEASE_NOTES}\", \"draft\": ${IS_DRAFT}, \"prerelease\": ${IS_PRERELEASE}}\'"
}
}
}
}
}
post {
// Notify only on null->failure or success->failure or any->success
failure {
script {
if(currentBuild.previousBuild == null) {
slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "RELEASE BUILD FAILED: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>")
}
}
}
regression {
slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "RELEASE BUILD FAILED: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>")
}
success {
script {
slackSend (channel: '#tobs-k8po-team', color: '#008000', message: "Success!! `wavefront-kubernetes-adapter:${VERSION_NUMBER}` released!")
}
}
always {
cleanWs()
}
}
}