-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJenkinsfile
More file actions
163 lines (147 loc) · 5.6 KB
/
Copy pathJenkinsfile
File metadata and controls
163 lines (147 loc) · 5.6 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Copyright (c) 2019-present Sonatype, Inc.
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
*/
@Library(['private-pipeline-library', 'jenkins-shared']) _
def seleniumHubDockerImage = 'docker-all.repo.sonatype.com/selenium/hub'
def seleniumDockerImage = 'docker-all.repo.sonatype.com/selenium/node-chrome'
def seleniumDockerVersion = '4.0.0-rc-1-prerelease-20210618'
def numSeleniumContainers = 1;
dockerizedBuildPipeline(
// expose gallery port on host so selenium container can hit it
dockerArgs: '-p 4043:4043',
prepare: {
githubStatusUpdate('pending')
withSonatypeDockerRegistry() {
sh """
docker network create grid
docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub \
${seleniumHubDockerImage}:${seleniumDockerVersion}
for i in \$(seq 1 ${numSeleniumContainers}); do
docker run --name selenium-chrome-\$i -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
-e SE_EVENT_BUS_PUBLISH_PORT=4442 \
-e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
-v /dev/shm:/dev/shm \
${seleniumDockerImage}:${seleniumDockerVersion}
done
"""
}
},
setVersion: {
env['VERSION'] = sh(returnStdout: true, script: 'jq -r -e .version lib/package.json').trim()
},
buildAndTest: {
// In this repo, all PRs must bump the version number so that master builds can be automatically released.
// This shell script enforces that
sh '''
# function that returns whether its first parameter is a versions string that is less than or equal to
# the second parameter
# From https://stackoverflow.com/a/4024263
verlte() {
[ "$1" = "`/bin/echo -e "$1\\n$2" | sort -V | head -n1`" ]
}
if [ "$BRANCH_NAME" != "master" ]; then
version=$VERSION
masterVersion=$(git cat-file blob origin/master:./lib/package.json | jq -r .version)
galleryVersion=$(jq -r .version gallery/package.json)
masterGalleryVersion=$(git cat-file blob origin/master:./gallery/package.json | jq -r .version)
if [ -z "$version" ] || [ -z "$masterVersion" ] || [ -z "$galleryVersion" ] || [ -z "$masterGalleryVersion" ];
then
echo 'Version lookups failed!'
exit 2
elif [ "$version" != "$galleryVersion" ]; then
echo 'Library and Gallery versions must match'
exit 1
elif [ "$version" = "$masterVersion" ] || [ "$galleryVersion" = "$masterGalleryVersion" ]; then
echo 'Package versions must be updated from what is on master'
exit 1
elif verlte "$version" "$masterVersion" || verlte "$galleryVersion" "$masterGalleryVersion"; then
echo 'Package versions must be higher than what is on master'
exit 1
fi
fi
'''
// As this is an open source project, yarn.lock URLs should point to npmjs.org, not repo.sonatype.com
sh '''
exitSuccessfully=0
for f in */yarn.lock; do
if ( grep --quiet 'repo\\.sonatype\\.com' "${f}" ); then
echo "repo.sonatype.com URL found in ${f}"
exitSuccessfully=1
fi
done
exit $exitSuccessfully
'''
withCredentials([string(credentialsId: 'REACT_SHARED_COMPONENTS_APPLITOOLS_KEY', variable: 'APPLITOOLS_API_KEY')]) {
sh """
registry=https://repo.sonatype.com/repository/npm-all/
cd lib
yarn install --registry "\${registry}"
npm run test
npm run build
cd dist
npm pack
cd ../..
cd gallery
yarn install --registry "\${registry}"
# Run the visual tests, hitting the selenium server on the host (which its port was forwarded to)
MAX_INSTANCES=${numSeleniumContainers} TEST_IP=\$JENKINS_AGENT_IP npm run test
npm run build
cd ..
"""
}
},
vulnerabilityScan: {
if (env.BRANCH_NAME == 'master') {
nexusPolicyEvaluation(
iqStage: 'release',
iqApplication: 'react-shared-components',
iqScanPatterns: [[scanPattern: 'gallery/webpack-modules']],
failBuildOnNetworkError: true
)
}
},
deploy: {
withCredentials([string(credentialsId: 'uxui-npm-auth-token', variable: 'NPM_TOKEN')]) {
withDockerImage(env.DOCKER_IMAGE_ID, 'npmjs-npmrc') {
sh 'npm publish --access public lib/dist/sonatype-react-shared-components-$VERSION.tgz'
}
}
},
postDeploy: {
sshagent(credentials: [sonatypeZionCredentialsId()]) {
sh '''
tag="v$VERSION"
git tag "$tag" && git push origin "$tag"
'''
}
},
archiveArtifacts: 'lib/dist/*.tgz,gallery/dist/**/*',
testResults: ['lib/junit.xml'],
onSuccess: {
githubStatusUpdate('success')
if (env.BRANCH_NAME == 'master') {
build job:'/uxui/publish-gallery-to-s3', propagate: false, wait: false, parameters: [
run(name: 'Producer', runId: "${currentBuild.fullProjectName}${currentBuild.displayName}")
]
}
},
onFailure: {
githubStatusUpdate('failure')
sendEmailNotification(currentBuild, env,
[[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], null)
},
cleanup: {
sh """
for i in \$(seq 1 ${numSeleniumContainers}); do
docker rm -f selenium-chrome-\$i
done
docker rm -f selenium-hub
docker rmi ${seleniumDockerImage}:${seleniumDockerVersion}
docker rmi ${seleniumHubDockerImage}:${seleniumDockerVersion}
docker network rm grid
"""
}
)