-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.github
129 lines (122 loc) · 3.48 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
121
122
123
124
125
126
127
128
129
library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/dhanarab/jenkins-pipeline-library.git'
]
)
)
githubOwner = 'AccelByte'
githubRepo = 'accelbyte-csharp-sdk'
githubSsh = 'accelbyte-sdk-sdkbuild-ssh'
githubPat = 'accelbyte-sdk-sdkbuild-pat-github'
bitbucketSsh = 'bitbucket-build-extend-ssh'
githubUrl = "[email protected]:${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'
}
}
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)
}
}
}
stage('PublishToNuget') {
when {
expression {
return ((params.ACTION == 'PUSH+RELEASE') || (params.ACTION == 'NUGET'))
}
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'nuget-accelbyte-csharp-sdk', passwordVariable: 'NUGET_TOKEN', usernameVariable: 'NUGET_EMAIL')]) {
sh "make pack_push NUGET_API_KEY=\$NUGET_TOKEN"
}
}
}
}
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)
}
}
}
}