-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile-release
145 lines (111 loc) · 5.18 KB
/
Jenkinsfile-release
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("titan-library") _
pipeline {
agent {label 'master' }
environment {
GITLAB_REPO = 'https://gitlab.tinkarbuild.com/FDA-Shield/tinkar-starter-bindings.git'
GITHUB_OWNER = "ikmdev"
GITHUB_REPO = "tinkar-starter-bindings"
GITHUB_REPO_GIT = "https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}.git"
GITHUB_RELEASE = "https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases"
WORKING_DIR = 'sourceRepo'
BRANCH = 'main'
RELEASE_NOTE = ''
VERSION = ''
MSG = ''
WEBHOOK_URL = "${GLOBAL_CHATOPS_URL}"
GITHUB_CREDS = credentials('github_ikmdev-pat')
}
options {
skipDefaultCheckout(false)
timestamps()
ansiColor('xterm')
}
stages {
stage('Prep') {
steps {
// Clean the working dir
sh "if [ -d $WORKING_DIR ]; then rm -Rf $WORKING_DIR; fi"
// Get the release information
script {
pomModel = readMavenPom(file: 'pom.xml')
pomVersion = pomModel.getVersion()
isSnapshot = pomVersion.contains("-SNAPSHOT")
repositoryId = 'maven-releases'
RELEASE_VERSION=pomVersion
RELEASE_MSG="release ${RELEASE_VERSION}"
echo "pomVersion: ${pomVersion}"
echo "isSnapshot: ${isSnapshot}"
}
sh "echo ${RELEASE_VERSION} '${RELEASE_MSG}'"
}
}
stage('Tag') {
steps {
withCredentials([gitUsernamePassword(credentialsId: 'gitlab-for-ikmdev-release-token', gitToolName: '')]) {
sh "git clone ${GITLAB_REPO} $WORKING_DIR"
}
dir("$WORKING_DIR") {
// set no-reply email address
sh 'git config --global user.email "120604367+pmaheshm@users.noreply.github.com"'
sh 'git config --global user.name "pmaheshm"'
// sh 'git config --global http.version HTTP/1.1'
// See what remotes are currently present
sh 'git remote -v'
// add a remote repository
sh "git remote add downstream ${GITHUB_REPO_GIT}"
// See what remotes are now available
sh 'git remote -v'
// Get the latest tag
//sh 'git describe --abbrev=0 --tags'
// Tag the branch
sh "git tag -a ${RELEASE_VERSION} -m '${RELEASE_MSG}'"
}
}
}
stage('Deploy') {
steps {
dir("$WORKING_DIR") {
withCredentials([gitUsernamePassword(credentialsId: 'gitlab-for-ikmdev-release-token', gitToolName: '')]) {
// Tag the origin repo
sh "git push origin ${RELEASE_VERSION}"
}
withCredentials([gitUsernamePassword(credentialsId: 'github_ikmdev-pat', gitToolName: '')]) {
// reset the author information on your last commit
//sh "git commit --amend --reset-author -m 'releasing version 1.1.0'"
// Push the new tag to downstream remote
sh "git push downstream ${RELEASE_VERSION}"
// Push the branch to downstream remote
sh "git push downstream ${BRANCH}"
}
}
}
}
stage('Create Release') {
environment {
GITHUB_OWNER = "ikmdev"
GITHUB_REPO = "tinkar-starter-bindings"
GITHUB_REPO_GIT = "https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}.git"
GITHUB_RELEASE = "https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases"
WORKING_DIR = 'sourceRepo'
BRANCH = 'main'
RELEASE_NOTE = ''
VERSION = ''
MSG = ''
WEBHOOK_URL = "${GLOBAL_CHATOPS_URL}"
GITHUB_CREDS = credentials('github_ikmdev-pat')
}
when{
expression{
branch=='main' && !isSnapshot
}
}
steps {
sh """
set -x
curl -u ${GITHUB_CREDS_USR}:${GITHUB_CREDS_PSW} -X POST -H 'Accept: application/vnd.github.v3+json' ${GITHUB_RELEASE} -d '{"tag_name":"${RELEASE_VERSION}","target_commitish":"main","name":"${RELEASE_MSG}","draft":false,"prerelease":false,"generate_release_notes":false,"body":"${RELEASE_MSG}"}'
echo "pushed to ikm github successfully"
"""
}
}
}
}