Skip to content

Commit 72fb51a

Browse files
committed
Migrate Jenkins server and fix an error when using torch=1.6.0.
1 parent ae79336 commit 72fb51a

File tree

2 files changed

+188
-176
lines changed

2 files changed

+188
-176
lines changed

Jenkinsfile

Lines changed: 187 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import hudson.tasks.test.AbstractTestResultAction
44

55
pipeline {
66
agent {
7-
docker {
8-
image 'pytorch/pytorch:latest'
9-
// host network is needed because mirrors are on the lan and resolved with /etc/hosts
10-
args '-u root:sudo --shm-size=1024m --gpus all --network=host'
7+
node {
8+
label 'node1'
119
}
1210
}
1311
environment {
@@ -18,194 +16,207 @@ pipeline {
1816
MKL_SERVICE_FORCE_INTEL = "1"
1917
}
2018
stages {
21-
stage('Install') {
22-
steps {
23-
sh 'nvidia-smi' // make sure gpus are loaded
24-
echo "Building branch: ${env.BRANCH_NAME}"
25-
echo "Building tag: ${env.TAG_NAME}"
26-
sh 'mkdir -p ~/.pip && touch ~/.pip/pip.conf'
27-
sh 'sed -i -r \'s|deb http://.+/ubuntu| deb [arch=amd64] http://apt.mirror.node2/ubuntu|g\' /etc/apt/sources.list'
28-
sh '''
29-
echo '
30-
[global]
31-
index-url = http://pypi.mirror.node2/root/pypi/+simple/
32-
trusted-host = pypi.mirror.node2
33-
[search]
34-
index = http://pypi.mirror.node2/root/pypi/
35-
' | tee ~/.pip/pip.conf'''
36-
retry(count: 3) {
37-
sh 'apt clean'
38-
sh 'apt update'
39-
sh 'apt -o APT::Acquire::Retries="3" --fix-missing install -y wget freeglut3-dev xvfb fonts-dejavu graphviz'
40-
// Instead of installing in development mode, we use normal to install
41-
// So that import errors can be detected.
42-
// sh 'pip install -e .'
43-
sh 'pip install .'
44-
sh 'pip install ./test_lib/multiagent-particle-envs/'
45-
sh 'pip install "gym[atari, box2d, classic_control]"'
46-
sh 'pip install mock pytest==6.0.0 pytest-cov==2.10.0 allure-pytest==2.8.16 pytest-xvfb==2.0.0 pytest-html==1.22.1 pytest-repeat==0.8.0'
47-
// This line must be included, otherwise matplotlib will
48-
// segfault when it tries to build the font cache.
49-
sh "python3 -c 'import matplotlib.pyplot as plt'"
19+
stage("All") {
20+
agent {
21+
docker {
22+
image 'pytorch/pytorch:1.6.0-cuda10.1-cudnn7-runtime'
23+
// host network is needed because mirrors are on the lan and resolved with /etc/hosts
24+
args '-u root:sudo --shm-size=1024m --gpus all --network=host'
25+
reuseNode true
5026
}
5127
}
52-
}
53-
stage('Test API') {
54-
steps {
55-
dir('test_api') {
56-
// run basic test
57-
sh 'ln -s ../test test'
58-
sh 'mkdir -p test_results'
59-
sh 'mkdir -p test_allure_data'
60-
// -eq 1 is used to tell jenkins to not mark
61-
// the test as failure when sub tests failed.
62-
sh 'python -m pytest ' +
63-
'-s --gpu_device="cuda:1" --assert=plain ' +
64-
'--cov-report term-missing --cov=machin ' +
65-
'-k \'not full_train\' ' +
66-
'-o junit_family=xunit1 ' +
67-
'--junitxml test_results/test_api.xml ' +
68-
'--cov-report xml:test_results/cov_report.xml ' +
69-
'--html=test_results/test_api.html ' +
70-
'--self-contained-html ' +
71-
'--alluredir="test_allure_data" ' +
72-
'. || [ $? -eq 1 ]'
73-
junit 'test_results/test_api.xml'
74-
archiveArtifacts 'test_results/test_api.html'
75-
archiveArtifacts 'test_results/cov_report.xml'
28+
29+
stages {
30+
stage('Install') {
31+
steps {
32+
sh 'nvidia-smi' // make sure gpus are loaded
33+
echo "Building branch: ${env.BRANCH_NAME}"
34+
echo "Building tag: ${env.TAG_NAME}"
35+
sh 'mkdir -p ~/.pip && touch ~/.pip/pip.conf'
36+
sh 'sed -i -r \'s|deb http://.+/ubuntu| deb [arch=amd64] http://apt.mirror.node2/ubuntu|g\' /etc/apt/sources.list'
37+
sh '''
38+
echo '
39+
[global]
40+
index-url = http://pypi.mirror.node2/root/pypi/+simple/
41+
trusted-host = pypi.mirror.node2
42+
[search]
43+
index = http://pypi.mirror.node2/root/pypi/
44+
' | tee ~/.pip/pip.conf'''
45+
retry(count: 3) {
46+
sh 'apt clean'
47+
sh 'apt update'
48+
sh 'apt -o APT::Acquire::Retries="3" --fix-missing install -y wget freeglut3-dev xvfb fonts-dejavu graphviz cmake g++ swig'
49+
// Instead of installing in development mode, we use normal to install
50+
// So that import errors can be detected.
51+
// sh 'pip install -e .'
52+
sh 'pip install .'
53+
sh 'pip install ./test_lib/multiagent-particle-envs/'
54+
sh 'pip install "gym[atari, box2d, classic_control]"'
55+
sh 'pip install mock pytest==6.0.0 pytest-cov==2.10.0 allure-pytest==2.8.16 pytest-xvfb==2.0.0 pytest-html==1.22.1 pytest-repeat==0.8.0'
56+
// This line must be included, otherwise matplotlib will
57+
// segfault when it tries to build the font cache.
58+
sh "python3 -c 'import matplotlib.pyplot as plt'"
59+
}
60+
}
7661
}
77-
}
78-
post {
79-
always {
80-
step([$class: 'CoberturaPublisher',
81-
autoUpdateHealth: false,
82-
autoUpdateStability: false,
83-
coberturaReportFile: 'test_api/test_results/cov_report.xml',
84-
failNoReports: false,
85-
failUnhealthy: false,
86-
failUnstable: false,
87-
maxNumberOfBuilds: 10,
88-
onlyStable: false,
89-
sourceEncoding: 'ASCII',
90-
zoomCoverageChart: false])
62+
stage('Test API') {
63+
steps {
64+
dir('test_api') {
65+
// run basic test
66+
sh 'ln -s ../test test'
67+
sh 'mkdir -p test_results'
68+
sh 'mkdir -p test_allure_data'
69+
// -eq 1 is used to tell jenkins to not mark
70+
// the test as failure when sub tests failed.
71+
sh 'python -m pytest ' +
72+
'-s --gpu_device="cuda:1" --assert=plain ' +
73+
'--cov-report term-missing --cov=machin ' +
74+
'-k \'not full_train\' ' +
75+
'-o junit_family=xunit1 ' +
76+
'--junitxml test_results/test_api.xml ' +
77+
'--cov-report xml:test_results/cov_report.xml ' +
78+
'--html=test_results/test_api.html ' +
79+
'--self-contained-html ' +
80+
'--alluredir="test_allure_data" ' +
81+
'. || [ $? -eq 1 ]'
82+
junit 'test_results/test_api.xml'
83+
archiveArtifacts 'test_results/test_api.html'
84+
archiveArtifacts 'test_results/cov_report.xml'
85+
}
86+
}
87+
post {
88+
always {
89+
step([$class: 'CoberturaPublisher',
90+
autoUpdateHealth: false,
91+
autoUpdateStability: false,
92+
coberturaReportFile: 'test_api/test_results/cov_report.xml',
93+
failNoReports: false,
94+
failUnhealthy: false,
95+
failUnstable: false,
96+
maxNumberOfBuilds: 10,
97+
onlyStable: false,
98+
sourceEncoding: 'ASCII',
99+
zoomCoverageChart: false])
100+
}
101+
}
91102
}
92-
}
93-
}
94-
stage('Test full training') {
95-
when {
96-
anyOf {
97-
branch 'release'
98-
tag pattern: 'v\\d+\\.\\d+\\.\\d+(-[a-zA-Z]+)?', comparator: "REGEXP"
103+
stage('Test full training') {
104+
when {
105+
anyOf {
106+
branch 'release'
107+
tag pattern: 'v\\d+\\.\\d+\\.\\d+(-[a-zA-Z]+)?', comparator: "REGEXP"
108+
}
109+
}
110+
steps {
111+
dir('test_full_train') {
112+
// run full training test
113+
sh 'ln -s ../test test'
114+
sh 'mkdir -p test_results'
115+
sh 'mkdir -p test_allure_data'
116+
sh 'python -m pytest ' +
117+
'-s --gpu_device="cuda:1" --assert=plain -k \'full_train\' ' +
118+
'-o junit_family=xunit1 ' +
119+
'--junitxml test_results/test_full_train.xml ' +
120+
'--html=test_results/test_full_train.html ' +
121+
'--self-contained-html ' +
122+
'--alluredir="test_allure_data" ' +
123+
'. || [ $? -eq 1 ]'
124+
junit 'test_results/test_full_train.xml'
125+
archiveArtifacts 'test_results/test_full_train.xml'
126+
archiveArtifacts 'test_results/test_full_train.html'
127+
}
128+
}
99129
}
100-
}
101-
steps {
102-
dir('test_full_train') {
103-
// run full training test
104-
sh 'ln -s ../test test'
105-
sh 'mkdir -p test_results'
106-
sh 'mkdir -p test_allure_data'
107-
sh 'python -m pytest ' +
108-
'-s --gpu_device="cuda:1" --assert=plain -k \'full_train\' ' +
109-
'-o junit_family=xunit1 ' +
110-
'--junitxml test_results/test_full_train.xml ' +
111-
'--html=test_results/test_full_train.html ' +
112-
'--self-contained-html ' +
113-
'--alluredir="test_allure_data" ' +
114-
'. || [ $? -eq 1 ]'
115-
junit 'test_results/test_full_train.xml'
116-
archiveArtifacts 'test_results/test_full_train.xml'
117-
archiveArtifacts 'test_results/test_full_train.html'
130+
stage('Check test result') {
131+
steps {
132+
script {
133+
def test_result_action = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
134+
test_passed = true
135+
if (test_result_action != null) {
136+
test_passed = test_result_action.getFailCount() == 0
137+
}
138+
if (test_passed) {
139+
println "Test passed"
140+
}
141+
else {
142+
println "Test failed"
143+
}
144+
}
145+
}
118146
}
119-
}
120-
}
121-
stage('Check test result') {
122-
steps {
123-
script {
124-
def test_result_action = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
125-
test_passed = true
126-
if (test_result_action != null) {
127-
test_passed = test_result_action.getFailCount() == 0
147+
stage('Deploy allure report') {
148+
when {
149+
anyOf {
150+
branch 'release'
151+
tag pattern: 'v\\d+\\.\\d+\\.\\d+(-[a-zA-Z]+)?', comparator: "REGEXP"
152+
}
128153
}
129-
if (test_passed) {
130-
println "Test passed"
154+
steps {
155+
// install allure and generate report
156+
sh 'mkdir -p test_allure_report'
157+
sh 'apt install -y default-jre'
158+
sh 'wget -O allure-commandline-2.8.1.tgz ' +
159+
'\'http://file.node2/allure-commandline-2.8.1.tgz\''
160+
sh 'tar -xvzf allure-commandline-2.8.1.tgz'
161+
sh 'chmod a+x allure-2.8.1/bin/allure'
162+
sh 'allure-2.8.1/bin/allure generate test_api/test_allure_data ' +
163+
'test_full_train/test_allure_data -o test_allure_report'
131164
}
132-
else {
133-
println "Test failed"
165+
post {
166+
always {
167+
// clean up remote directory and copy this report to the server
168+
sshPublisher(publishers: [sshPublisherDesc(
169+
configName: 'ci.beyond-infinity.com',
170+
transfers: [sshTransfer(
171+
cleanRemote: true,
172+
excludes: '',
173+
execCommand: '',
174+
execTimeout: 120000,
175+
flatten: false,
176+
makeEmptyDirs: false,
177+
noDefaultExcludes: false,
178+
patternSeparator: '[, ]+',
179+
remoteDirectory: "reports/machin/${env.TAG_NAME}/",
180+
remoteDirectorySDF: false,
181+
removePrefix: 'test_allure_report/', // remove prefix
182+
sourceFiles: 'test_allure_report/**/*' // recursive copy
183+
)],
184+
usePromotionTimestamp: false,
185+
useWorkspaceInPromotion: false, verbose: false)])
186+
}
134187
}
135188
}
136-
}
137-
}
138-
stage('Deploy allure report') {
139-
when {
140-
anyOf {
141-
branch 'release'
142-
tag pattern: 'v\\d+\\.\\d+\\.\\d+(-[a-zA-Z]+)?', comparator: "REGEXP"
143-
}
144-
}
145-
steps {
146-
// install allure and generate report
147-
sh 'mkdir -p test_allure_report'
148-
sh 'apt install -y default-jre'
149-
sh 'wget -O allure-commandline-2.8.1.tgz ' +
150-
'\'http://file.node2/allure-commandline-2.8.1.tgz\''
151-
sh 'tar -xvzf allure-commandline-2.8.1.tgz'
152-
sh 'chmod a+x allure-2.8.1/bin/allure'
153-
sh 'allure-2.8.1/bin/allure generate test_api/test_allure_data ' +
154-
'test_full_train/test_allure_data -o test_allure_report'
155-
}
156-
post {
157-
always {
158-
// clean up remote directory and copy this report to the server
159-
sshPublisher(publishers: [sshPublisherDesc(
160-
configName: 'ci.beyond-infinity.com',
161-
transfers: [sshTransfer(
162-
cleanRemote: true,
163-
excludes: '',
164-
execCommand: '',
165-
execTimeout: 120000,
166-
flatten: false,
167-
makeEmptyDirs: false,
168-
noDefaultExcludes: false,
169-
patternSeparator: '[, ]+',
170-
remoteDirectory: "reports/machin/${env.TAG_NAME}/",
171-
remoteDirectorySDF: false,
172-
removePrefix: 'test_allure_report/', // remove prefix
173-
sourceFiles: 'test_allure_report/**/*' // recursive copy
174-
)],
175-
usePromotionTimestamp: false,
176-
useWorkspaceInPromotion: false, verbose: false)])
177-
}
178-
}
179-
}
180-
stage('Deploy PyPI package') {
181-
when {
182-
allOf {
183-
// only version tags without postfix will be deployed
184-
tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: "REGEXP"
185-
expression { test_passed }
189+
stage('Deploy PyPI package') {
190+
when {
191+
allOf {
192+
// only version tags without postfix will be deployed
193+
tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: "REGEXP"
194+
expression { test_passed }
195+
}
196+
}
197+
steps {
198+
// build distribution wheel
199+
sh 'python3 -m pip install twine'
200+
sh 'python3 setup.py sdist bdist_wheel'
201+
// upload to twine
202+
sh 'twine upload dist/*'
203+
}
204+
post {
205+
always {
206+
// save results for later check
207+
archiveArtifacts (allowEmptyArchive: true,
208+
artifacts: 'dist/*whl',
209+
fingerprint: true)
210+
}
211+
}
186212
}
187213
}
188-
steps {
189-
// build distribution wheel
190-
sh 'python3 -m pip install twine'
191-
sh 'python3 setup.py sdist bdist_wheel'
192-
// upload to twine
193-
sh 'twine upload dist/*'
194-
}
195214
post {
196215
always {
197-
// save results for later check
198-
archiveArtifacts (allowEmptyArchive: true,
199-
artifacts: 'dist/*whl',
200-
fingerprint: true)
216+
// clean up workspace
217+
sh 'rm -rf ./*'
201218
}
202219
}
203220
}
204221
}
205-
post {
206-
always {
207-
// clean up workspace
208-
sh 'rm -rf ./*'
209-
}
210-
}
211222
}

0 commit comments

Comments
 (0)