-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile.github
120 lines (114 loc) · 3.47 KB
/
Jenkinsfile.github
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/dhanarab/jenkins-pipeline-library.git'
]
)
)
githubOwner = 'AccelByte'
githubRepo = 'accelbyte-java-sdk'
githubSsh = 'accelbyte-sdk-sdkbuild-ssh'
githubPat = 'accelbyte-sdk-sdkbuild-pat-github'
bitbucketSsh = 'bitbucket-build-extend-ssh'
githubUrl = "git@github.com:${githubOwner}/${githubRepo}.git"
jobChannel = env.SLACK_CHANNEL_ACTIVITY_EXTEND_CODEGEN_SDK ? env.SLACK_CHANNEL_ACTIVITY_EXTEND_CODEGEN_SDK : "#activity-justice-codegen-sdk"
pipeline {
agent {
label "extend-builder-batch"
}
stages {
stage('Prepare') {
steps {
script {
currentBuild.displayName = "#${env.BUILD_NUMBER} ${params.ACTION}"
gitHost = sh(script: "echo '${githubUrl}' | grep -oP '(?<=@).+(?=:)'", returnStdout: true).trim()
sh "grep -q ${gitHost} ~/.ssh/known_hosts || ssh-keyscan ${gitHost} | tee -a ~/.ssh/known_hosts"
}
}
}
stage('Push') {
when {
expression {
return params.ACTION == 'PUSH'
}
}
steps {
script {
sh "git checkout master"
sshagent(credentials: [githubSsh])
{
sh "git push ${githubUrl} HEAD:main"
}
}
}
}
stage('Release') {
when {
expression {
return params.ACTION == 'PUSH+RELEASE'
}
}
environment {
PUBLISH_OSSRH = credentials('maven-central-accelbyte')
PUBLISH_ASC_KEY_FILE_PATH = credentials('maven-central-accelbyte-signing-key')
PUBLISH_ASC_KEY_PASSWORD = credentials('maven-central-accelbyte-signing-password')
}
steps {
script {
if (params.RELEASE_NOTE ==~ /(?s).*@[A-Za-z0-9_-]+@.*/)
{
echo 'Release note still contains one or more template placeholders e.g. @VERSION@, etc. Please check.'
sh 'false' // Fail this job
}
sh "git checkout ${params.RELEASE_BRANCH}"
sshagent(credentials: [githubSsh])
{
if (params.RELEASE_BRANCH == "master") {
sh "git push ${githubUrl} HEAD:main"
}
else {
sh "git push ${githubUrl} HEAD:${params.RELEASE_BRANCH}"
}
sh "git push ${githubUrl} ${params.RELEASE_TAG}"
}
github.createRelease(githubPat, githubOwner, githubRepo, params.RELEASE_TAG, params.RELEASE_TAG, params.RELEASE_NOTE)
sh 'make publish PUBLISH_OSSRH_USERNAME="$PUBLISH_OSSRH_USR" PUBLISH_OSSRH_PASSWORD="$PUBLISH_OSSRH_PSW" PUBLISH_ASC_KEY="$(cat "$PUBLISH_ASC_KEY_FILE_PATH")" PUBLISH_ASC_KEY_PASSWORD="$PUBLISH_ASC_KEY_PASSWORD"'
}
}
}
stage('Pull') {
when {
expression {
return params.ACTION == 'PULL'
}
}
steps {
script {
sh "git checkout master"
sshagent(credentials: [githubSsh])
{
sh "git pull ${githubUrl} main"
}
sshagent(credentials: [bitbucketSsh])
{
sh "git push"
}
}
}
}
}
post {
failure {
script {
message = """
:no_entry: <${env.BUILD_URL}|${env.JOB_NAME}-${env.BUILD_NUMBER}> *failed*
|*Action*
|${params.ACTION}
|""".stripMargin()
slackSend(channel: jobChannel, color: '#FF0000', message: message)
}
}
}
}