-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
112 lines (106 loc) · 3.92 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
pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: nodejs
image: femorao/pnpm:7
env:
- name: "npm_config_cache"
value: /home/jenkins/.npm-cache
command:
- sleep
args:
- 9999999
volumeMounts:
- name: npm-cache-vol
mountPath: /home/jenkins/.npm-cache
- name: pnpm-vol
mountPath: /home/jenkins/.pnpm
- name: gitversion
image: gittools/gitversion
command:
- sleep
args:
- 9999999
restartPolicy: Never
volumes:
- name: npm-cache-vol
persistentVolumeClaim:
claimName: npm-cache-pvc
- name: pnpm-vol
persistentVolumeClaim:
claimName: pnpm-pvc
"""
}
}
parameters {
booleanParam(name: 'DRY_RUN', defaultValue: false, description: '')
}
stages {
stage('Version') {
steps {
withCredentials([string(credentialsId: 'discord-hook', variable: 'DISCORD_HOOK')]) {
discordSend description: "Building branch: ${BRANCH_NAME}", footer: '', image: '', link: '', result: '', scmWebUrl: '', showChangeset: false, thumbnail: '', title: 'Build Started', webhookURL: DISCORD_HOOK
}
sh 'git branch -a | grep remotes | sed \'s/remotes\\/[^\\/]*\\///g\' | while read branch; do git checkout $branch; done'
sh 'git checkout $BRANCH_NAME'
container('gitversion') {
configFileProvider([configFile(fileId: 'default-gitversion', targetLocation: 'GitVersion.yml')]) {
sh "/tools/dotnet-gitversion"
sh "/tools/dotnet-gitversion /output json /showvariable SemVer > ${WORKSPACE}/version"
}
}
}
}
stage('Install') {
steps {
container('nodejs') {
sh 'echo "store-dir=/home/jenkins/.pnpm" > .npmrc'
sh "pnpm install"
}
}
}
stage('Build') {
steps {
container('nodejs') {
sh "find ${WORKSPACE}/apps ${WORKSPACE}/libs -name package.json | sed s/package\\.json//g | while read package; do cd \$package; npm version --no-git-tag-version \$(cat ${WORKSPACE}/version); done"
sh "pnpm build"
sh "cp libs/web/package.json dist/libs/web"
sh "sed -i s/moxy-js-version/\$(cat ${WORKSPACE}/version)/g dist/apps/cli/package.json"
sh "ls -1a dist/*/*/package.json | sed s/package\\.json//g | while read package; do cp LICENSE \$package; done"
}
}
}
stage('Publish') {
steps {
container('nodejs') {
withCredentials([string(credentialsId: 'npm-publish ', variable: 'NPM_TOKEN')]) {
sh "npm config set '//registry.npmjs.org/:_authToken' \"\${NPM_TOKEN}\""
script {
if(params.DRY_RUN == true) {
sh "ls -1a ${WORKSPACE}/dist/*/*/package.json | sed s/package\\.json//g | while read package; do cd \$package; npm publish --dry-run; done"
} else {
sh "ls -1a ${WORKSPACE}/dist/*/*/package.json | sed s/package\\.json//g | while read package; do cd \$package; npm publish --access public; done"
}
}
}
}
}
}
}
post {
always {
withCredentials([string(credentialsId: 'discord-hook', variable: 'DISCORD_HOOK')]) {
script {
def SEMVER = readFile "${WORKSPACE}/version"
def GIT_COMMIT_MSG = sh (script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true).trim()
discordSend description: "Build finished for branch: ${BRANCH_NAME}, version ${SEMVER}", footer: GIT_COMMIT_MSG, image: '', link: '', result: currentBuild.result, scmWebUrl: '', thumbnail: '', title: 'Build Finished', webhookURL: DISCORD_HOOK
}
}
}
}
}