This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
141 lines (127 loc) · 3.46 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
@Library('pipeline-library')
import com.genesys.jenkins.Service
def notifications = null
def isReleaseBranch() {
return env.SHORT_BRANCH.equals('main');
}
pipeline {
agent { label 'dev_mesos_v2' }
options {
quietPeriod(480)
disableConcurrentBuilds()
}
environment {
NPM_UTIL_PATH = "npm-utils"
REPO_DIR = "repo"
SHORT_BRANCH = env.GIT_BRANCH.replaceFirst(/^origin\//, '');
}
tools {
nodejs 'NodeJS 12.13.0'
}
stages {
stage('Setup parameters') {
steps {
script {
properties([
parameters([
string(
defaultValue: '',
name: 'EMAIL_LIST',
description: '',
trim: true
),
string(
defaultValue: '',
name: 'NPM_CREDENTIALS_ID',
trim: true
),
string(
defaultValue: '',
name: 'GITHUB_CREDENTIALS_ID',
trim: true
)
])
])
}
}
}
stage('Import notifications lib') {
steps {
script {
// clone pipelines repo
dir('pipelines') {
git branch: 'master',
url: '[email protected]:inindca/pipeline-library.git',
changelog: false
notifications = load 'src/com/genesys/jenkins/Notifications.groovy'
}
}
}
}
stage('Checkout') {
steps {
deleteDir()
dir(env.REPO_DIR) {
checkout scm
// Make a local branch so we can work with history and push (there's probably a better way to do this)
sh "git checkout -b ${env.SHORT_BRANCH}"
}
}
}
stage('Avoid Build Loop') {
steps {
script {
dir(env.REPO_DIR) {
def lastCommit = sh(script: 'git log -n 1 --format=%s', returnStdout: true).trim()
if (lastCommit.startsWith('chore(release)')) {
currentBuild.description = 'Skipped'
currentBuild.result = 'ABORTED'
error('Last commit was a release, exiting build process.')
}
}
}
}
}
stage('Prep') {
steps {
sh "git clone --single-branch -b master --depth=1 [email protected]:inindca/npm-utils.git ${env.NPM_UTIL_PATH}"
}
}
stage('Publish Library') {
when {
expression { isReleaseBranch() }
}
steps {
withCredentials([string(credentialsId: "${params.NPM_CREDENTIALS_ID}", variable: 'NPM_TOKEN')]) {
dir(env.REPO_DIR) {
sh '''
echo "registry=https://registry.npmjs.org" > ./.npmrc
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ./.npmrc
'''
sh "${env.WORKSPACE}/${env.NPM_UTIL_PATH}/scripts/auto-version-bump.sh"
// Do not include the Jenkinsfile in the published package.
sh '''
echo "Jenkinsfile" >> .npmignore
npm publish 1>&2
'''
sshagent (credentials: ["${params.GITHUB_CREDENTIALS_ID}"]) {
sh "git push --tags -u origin ${env.SHORT_BRANCH}"
}
}
}
}
}
}
post {
fixed {
script {
notifications.emailResults(params.EMAIL_LIST)
}
}
failure {
script {
notifications.emailResults(params.EMAIL_LIST)
}
}
}
}