forked from ariatemplates/git-release-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
38 lines (32 loc) · 1.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
stage('publish') {
node('redshelf') {
checkout scm;
env.TAG_NAME = shWithReturn('git describe --exact-match --tags HEAD || :');
if(isTagBuild()) {
env.TAG_NAME = env.TAG_NAME.substring(0, env.TAG_NAME.length() - 1);
env.DOCKER_TAG = dockerTag(env.TAG_NAME);
env.NPM_TAG = 'stable';
} else {
env.TAG_NAME = "";
env.DOCKER_TAG = "";
env.NPM_TAG = "";
}
if(env.DOCKER_TAG != "") {
withCredentials([string(credentialsId: 'npm-token', variable: 'NPM_TOKEN')]) {
sh 'sudo -E docker build --build-arg NPM_TOKEN=$NPM_TOKEN -t ${DOCKER_TAG} .';
sh 'sudo -E docker run -e "NPM_TOKEN=$NPM_TOKEN" ${DOCKER_TAG} bash -c "npm --no-git-tag-version version ${TAG_NAME} && npm publish --tag ${NPM_TAG}"';
sh "sudo -E docker push ${DOCKER_TAG}";
}
}
}
}
def dockerTag(buildName) {
return "redshelf/git-release-notes:${buildName}";
}
def isTagBuild() {
return env.TAG_NAME && env.TAG_NAME != "";
}
def shWithReturn(script) {
returnVal = sh(returnStdout: true, script: script);
return returnVal;
}