Repository navigation
Expand file tree
/
Copy pathJenkinsfile.github
More file actions
145 lines (129 loc) · 4.42 KB
/
Copy pathJenkinsfile.github
File metadata and controls
145 lines (129 loc) · 4.42 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/AccelByte/extend-jenkins-pipeline-library.git'
]
)
)
githubOwner = 'AccelByte'
githubRepo = 'accelbyte-python-modular-sdk'
githubSsh = 'accelbyte-sdk-sdkbuild-ssh'
githubPat = 'accelbyte-sdk-sdkbuild-pat-github'
bitbucketSsh = 'bitbucket-build-extend-ssh'
githubUrl = "git@github.com:${githubOwner}/${githubRepo}.git"
agentLabel = params.ACTION == 'PUSH+RELEASE' ? 'extend-builder-ci && linux-amd64' : 'extend-builder-ci'
jobChannel = '#activity-extend-codegen-modular-sdk'
pipeline {
agent {
label "${agentLabel}"
}
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 {
releaseNote = params.RELEASE_NOTE
if (params.AGS_VERSION != "None") {
releaseNote = releaseNote.replace('@VERSION@', params.AGS_VERSION)
}
if (releaseNote ==~ /(?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])
{
echo "Check if tag `ags/v${params.AGS_VERSION}` is exists"
def tagCheck = sh(script: "git tag | grep 'ags/v${params.AGS_VERSION}'", returnStdout: true, returnStatus: true)
if (tagCheck == "") {
echo "AGS version tag 'ags/v${params.AGS_VERSION}' does not exists in source repository."
sh 'false' // Fail this job
}
if (params.RELEASE_BRANCH == "master") {
echo 'Push bitbucket master to github main'
sh "git push ${githubUrl} HEAD:main"
}
else {
echo "Push bitbucket '${params.RELEASE_BRANCH}' to github"
sh "git push ${githubUrl} HEAD:${params.RELEASE_BRANCH}"
}
echo "Tag github with ags version"
sh "git push ${githubUrl} 'ags/v${params.AGS_VERSION}'"
echo "Get all tags related to 'ags/v${params.AGS_VERSION}' and push them"
sh "git tag --contains \$(git rev-list -n 1 'ags/v${params.AGS_VERSION}') | grep -v 'ags/v${params.AGS_VERSION}' | xargs -I{} sh -c 'git push ${githubUrl} '{}' || exit 255'"
releaseName = "AccelByte Python Extend Modular SDK for AGS v${params.AGS_VERSION}"
github.createRelease(githubPat, githubOwner, githubRepo, "ags/v${params.AGS_VERSION}", releaseName, releaseNote)
withCredentials([file(credentialsId: 'justice-codegen-sdk-pypirc', variable: 'PYPIRC_PATH')]) {
sh "sudo apt install -y jq"
sh 'make build_all upload_all PYPIRC_PATH=$PYPIRC_PATH'
}
}
}
}
}
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)
}
}
}
}