forked from AccelByte/accelbyte-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.github
102 lines (96 loc) · 2.41 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
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 = 'dhanarab-sdkbuild-ssh'
githubPat = 'dhanarab-sdkbuild-pat-github'
bitbucketSsh = 'build_account_bitbucket_key'
githubUrl = "[email protected]:${githubOwner}/${githubRepo}.git"
pipeline {
agent {
label "master"
}
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' || params.ACTION == 'PUSH+RELEASE'
}
}
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 {
sh "git checkout master"
sshagent(credentials: [githubSsh])
{
sh "git push ${githubUrl} ${params.RELEASE_TAG}"
}
github.createRelease(githubPat, githubOwner, githubRepo, params.RELEASE_TAG)
}
}
}
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: "#activity-justice-codegen-sdk", color: '#FF0000', message: message)
}
}
}
}