-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
executable file
·76 lines (73 loc) · 3.14 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
@Library('apim-jenkins-lib@master') _
pipeline {
agent { label 'default' }
environment {
ARTIFACTORY_CREDS = credentials('ARTIFACTORY_USERNAME_TOKEN')
ARTIFACTORY_ARTIFACT_PATH = 'usw1.packages.broadcom.com/artifactory'
ARTIFACTORY_ARTIFACT_NPM_DEV_PATH = "${env.ARTIFACTORY_ARTIFACT_PATH}/api/npm/apim-npm-dev-local/"
ARTIFACTORY_ARTIFACT_NPM_RELEASE_PATH = "${env.ARTIFACTORY_ARTIFACT_PATH}/api/npm/apim-npm-release-local/"
ARTIFACTORY_UPLOAD_PATH = "${env.ARTIFACTORY_ARTIFACT_PATH}/apim-npm-dev-local/graphman-cli/"
ARTIFACTORY_EMAIL = '[email protected]'
}
parameters {
string(name: 'VAR_jdk_version', defaultValue: 'jdk11.0.18_10', description: 'JDK Version')
booleanParam(
defaultValue: false,
description: 'true to publish the build artifacts to the artifactory.',
name: 'PUBLISH_TO_ARTIFACTORY'
)
}
stages {
stage('Update Java') {
steps {
script {
sh 'java -version'
sh 'cd /usr/java; rm -rf default; ln -s ${VAR_jdk_version} default'
sh 'cd /usr/java; rm -rf latest; ln -s ${VAR_jdk_version} latest'
jdk_path="/usr/java/${VAR_jdk_version}"
sh 'java -version'
}
}
}
stage("Build") {
steps {
echo "Building graphman-client ..."
script {
sh './build.sh $BUILD_NUMBER $BRANCH_NAME'
sh "mkdir -p BuildArtifact"
sh "du -h"
sh "cp ./build/dist/layer7-graphman-* BuildArtifact"
}
}
}
stage('Publish to Artifactory') {
when { expression { params.PUBLISH_TO_ARTIFACTORY }}
steps {
sh '''
echo prepare per-project npmrc file
export ARTIFACTORY_ARTIFACT_NPM_PATH=$ARTIFACTORY_ARTIFACT_NPM_DEV_PATH
if [[ $BRANCH_NAME == release/v* ]]; then export ARTIFACTORY_ARTIFACT_NPM_PATH=$ARTIFACTORY_ARTIFACT_NPM_RELEASE_PATH; fi
artifactoryCredentials=$(echo -n $ARTIFACTORY_CREDS_USR:$ARTIFACTORY_CREDS_PSW|base64 --wrap=0)
echo registry=https://$ARTIFACTORY_ARTIFACT_NPM_PATH > ./.npmrc
echo _auth=$artifactoryCredentials >> ./.npmrc
echo email=$ARTIFACTORY_EMAIL >> ./.npmrc
echo always-auth=true >> ./.npmrc
cat ./.npmrc
echo start publishing the artifacts
layer7Graphman=$(ls -d ./build/dist/layer7-graphman-*.tgz)
npm publish ${layer7Graphman} --registry https://${ARTIFACTORY_ARTIFACT_NPM_PATH}
rm -rf ./.npmrc
'''
echo "published Graphman-client artifacts to artifactory"
}
}
}
post {
always {
script {
archiveArtifacts artifacts: "BuildArtifact/**/*", allowEmptyArchive: true
}
echo "end"
}
}
}