-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
119 lines (99 loc) · 3.02 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
#!groovy
pipeline {
agent {
docker {
image 'node:14.15.1'
label 'docker'
}
}
environment {
HOME = "${env.WORKSPACE}"
}
stages {
stage('Set Version') {
when {
branch pattern: 'release/*', comparator: 'GLOB'
}
steps {
// fetch all remotes from origin
sh 'git config "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"'
sh 'git fetch --all'
sh "git checkout ${env.BRANCH_NAME}"
sh "git reset --hard origin/${env.BRANCH_NAME}"
sh "git tag -d ${releaseVersion} || true"
// read version from brach, set it and commit it
sh "yarn version --no-git-tag-version --new-version ${releaseVersion}"
sh 'git add package.json'
commit "release version ${releaseVersion}"
// checkout, reset and merge
sh 'git checkout main'
sh 'git reset --hard origin/main'
sh "git merge --ff-only ${env.BRANCH_NAME}"
// set tag
tag releaseVersion
}
}
stage('Install') {
steps {
sh 'yarn install'
}
}
stage('Check') {
steps {
sh 'yarn run check'
}
}
stage('Deployment') {
when {
branch pattern: 'release/*', comparator: 'GLOB'
}
steps {
withYarnAuth('npm-token-scm-manager') {
sh "yarn publish --new-version ${releaseVersion}"
}
}
}
stage('Update Repository') {
when {
branch pattern: 'release/*', comparator: 'GLOB'
}
steps {
// merge main in to develop
sh 'git checkout develop'
sh 'git merge main'
// push changes back to remote repository
authGit 'SCM-Manager', 'push origin main --tags'
authGit 'SCM-Manager', 'push origin develop --tags'
authGit 'SCM-Manager', "push origin :${env.BRANCH_NAME}"
}
}
}
}
String getReleaseVersion() {
return env.BRANCH_NAME.substring("release/".length());
}
void commit(String message) {
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' commit -m '${message}'"
}
void tag(String version) {
String message = "release version ${version}"
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' tag -m '${message}' ${version}"
}
void withYarnAuth(String credentials, Closure<Void> closure) {
withCredentials([string(credentialsId: credentials, variable: 'NPM_TOKEN')]) {
writeFile encoding: 'UTF-8', file: '.npmrc', text: "//registry.npmjs.org/:_authToken='${NPM_TOKEN}'"
writeFile encoding: 'UTF-8', file: '.yarnrc', text: '''
registry "https://registry.npmjs.org/"
always-auth true
email cesmarvin@cloudogu.com
'''.trim()
closure.call()
}
}
void authGit(String credentials, String command) {
withCredentials([
usernamePassword(credentialsId: credentials, usernameVariable: 'AUTH_USR', passwordVariable: 'AUTH_PSW')
]) {
sh "git -c credential.helper=\"!f() { echo username='\$AUTH_USR'; echo password='\$AUTH_PSW'; }; f\" ${command}"
}
}