forked from logdna/terraform-provider-logdna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
158 lines (140 loc) · 4.04 KB
/
Jenkinsfile
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
146
147
148
149
150
151
152
153
154
155
156
157
158
library 'magic-butler-catalogue'
def PROJECT_NAME = 'terraform-provider-logdna'
def CURRENT_BRANCH = currentBranch()
def MAIN_BRANCH = 'main'
def GIT_REPO = 'logdna/terraform-provider-logdna'
def GIT_AUTHOR = 'logdnabot'
def TRIGGER_PATTERN = ".*@logdnabot.*"
def GetRepoName() {
def parsed_url = GIT_URL.tokenize('/')
return parsed_url[2].split("\\.")[0] + "/" + parsed_url[3].split("\\.")[0]
}
pipeline {
agent none
options {
timestamps()
ansiColor 'xterm'
}
triggers {
issueCommentTrigger(TRIGGER_PATTERN)
}
stages {
stage('Validate PR Source') {
when {
expression { env.CHANGE_FORK }
not {
triggeredBy 'issueCommentCause'
}
}
steps {
error('A maintainer needs to approve this PR for CI by commenting')
}
}
stage('Test') {
agent {
node {
label 'ec2-fleet'
customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}"
}
}
environment {
GIT_BRANCH = "${CURRENT_BRANCH}"
GIT_REPO = "${GIT_REPO}"
CURRENT_REPO = GetRepoName()
MAKEFLAGS='-j1'
}
steps {
script {
withCredentials([
string(credentialsId: 'logdna-gpg-key', variable: 'GPG_KEY'),
string(credentialsId: 'terraform-provider-servicekey', variable: 'SERVICE_KEY'),
string(credentialsId: 'terraform-provider-coveralls', variable: 'COVERALLS_TOKEN'),
string(credentialsId: 'terraform-test-s3-bucket', variable: 'S3_BUCKET'),
string(credentialsId: 'terraform-test-gcs-bucket', variable: 'GCS_BUCKET'),
string(credentialsId: 'terraform-test-gcs-projectid', variable: 'GCS_PROJECTID')
]) {
sh '''
set +x
echo "$GPG_KEY" > gpgkey.asc
make postcov
make test-release
'''
}
if (CURRENT_REPO == GIT_REPO) {
sh '''
set +x
git checkout -b ${GIT_BRANCH} origin/${GIT_BRANCH}
git fetch --tags
export CURRENT_TAG=$(make version-current)
export NEXT_TAG=$(make version-next)
echo "Latest: ${CURRENT_TAG}"
echo "Next: ${NEXT_TAG}"
'''
}
}
}
post {
always {
sh 'rm -f gpgkey.asc'
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'coverage/',
reportFiles: '*.html',
reportName: 'Code Coverage'
]
archiveArtifacts 'dist/*'
}
}
}
stage('Release') {
when {
beforeAgent true
branch MAIN_BRANCH
}
agent {
node {
label 'ec2-fleet'
customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}"
}
}
environment {
GIT_BRANCH = "${CURRENT_BRANCH}"
GIT_AUTHOR = "${GIT_AUTHOR}"
GIT_REPO = "${GIT_REPO}"
MAKEFLAGS='-j1'
}
steps {
script {
withCredentials([
string(credentialsId: 'logdna-gpg-key', variable: 'GPG_KEY'),
string(credentialsId: 'github-api-token', variable: 'GITHUB_TOKEN')
]) {
configFileProvider([configFile(fileId: 'git-askpass', variable: 'GIT_ASKPASS')]) {
sh 'chmod +x \$GIT_ASKPASS'
sh '''
set +x
git checkout -b ${GIT_BRANCH} origin/${GIT_BRANCH}
git config user.name "LogDNA Bot"
git config user.email "[email protected]"
git fetch --tags
export NEXT_TAG=$(make version-next)
echo "Creating release for ${NEXT_TAG}"
git tag ${NEXT_TAG}
git push origin ${NEXT_TAG}
echo "$GPG_KEY" > gpgkey.asc
make release
'''
}
}
}
}
post {
always {
sh 'rm -f gpgkey.asc'
}
}
}
}
}