-
Notifications
You must be signed in to change notification settings - Fork 12
/
Jenkinsfile
143 lines (128 loc) · 3.75 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
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.*"
pipeline {
agent {
node {
label 'ec2-fleet'
customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}"
}
}
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') {
environment {
GIT_BRANCH = "${CURRENT_BRANCH}"
CHANGE_FORK = "${CHANGE_FORK}"
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
'''
}
// NOTE Version validation will be run only for a non fork branch
if (CHANGE_FORK == null) {
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 {
branch MAIN_BRANCH
}
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'
}
}
}
}
}