Merge "Remove port from NEXUS_URL for netrc"
[releng/global-jjb.git] / .jjb-test / expected-xml / github-ciman-jjb-deploy-job
1 <?xml version="1.0" encoding="utf-8"?>
2 <project>
3   <actions/>
4   <description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
5   <keepDependencies>false</keepDependencies>
6   <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
7   <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
8   <concurrentBuild>true</concurrentBuild>
9   <assignedNode>build-vm</assignedNode>
10   <canRoam>false</canRoam>
11   <properties>
12     <com.coravy.hudson.plugins.github.GithubProjectProperty>
13       <projectUrl>$GIT_URL/$GERRIT_PROJECT/example-org/releng/ciman</projectUrl>
14     </com.coravy.hudson.plugins.github.GithubProjectProperty>
15     <hudson.model.ParametersDefinitionProperty>
16       <parameterDefinitions>
17         <hudson.model.StringParameterDefinition>
18           <name>PROJECT</name>
19           <description>Parameter to identify a Gerrit project. This is typically the
20 project repo path as exists in Gerrit.
21 For example: ofextensions/circuitsw
22 </description>
23           <defaultValue>releng/ciman</defaultValue>
24         </hudson.model.StringParameterDefinition>
25         <hudson.model.StringParameterDefinition>
26           <name>STREAM</name>
27           <description>Stream is often set to the same name as 'branch' but can
28 sometimes be used as a name representing a project's release code
29 name.
30 </description>
31           <defaultValue>master</defaultValue>
32         </hudson.model.StringParameterDefinition>
33         <hudson.model.StringParameterDefinition>
34           <name>GERRIT_PROJECT</name>
35           <description>Parameter to identify Gerrit project. This is typically the
36 project repo path as exists in Gerrit.
37 For example: ofextensions/circuitsw
38
39 Note that Gerrit will override this parameter automatically if a
40 job is triggered by Gerrit.
41 </description>
42           <defaultValue>releng/ciman</defaultValue>
43         </hudson.model.StringParameterDefinition>
44         <hudson.model.StringParameterDefinition>
45           <name>GERRIT_BRANCH</name>
46           <description>Parameter to identify a Gerrit branch.
47
48 Note that Gerrit will override this parameter automatically if a
49 job is triggered by Gerrit.
50 </description>
51           <defaultValue>master</defaultValue>
52         </hudson.model.StringParameterDefinition>
53         <hudson.model.StringParameterDefinition>
54           <name>GERRIT_REFSPEC</name>
55           <description>Parameter to identify a refspec when pulling from Gerrit.
56
57 Note that Gerrit will override this parameter automatically if a
58 job is triggered by Gerrit.
59 </description>
60           <defaultValue>refs/heads/master</defaultValue>
61         </hudson.model.StringParameterDefinition>
62         <hudson.model.StringParameterDefinition>
63           <name>LFTOOLS_VERSION</name>
64           <description>Version of lftools to install. Can be a specific version like
65 '0.6.0' or a PEP-440 definition.
66 https://www.python.org/dev/peps/pep-0440/
67 For example '&lt;1.0.0' or '&gt;=1.0.0,&lt;2.0.0'.
68 </description>
69           <defaultValue>&lt;1.0.0</defaultValue>
70         </hudson.model.StringParameterDefinition>
71       </parameterDefinitions>
72     </hudson.model.ParametersDefinitionProperty>
73   </properties>
74   <scm class="hudson.plugins.git.GitSCM">
75     <configVersion>2</configVersion>
76     <userRemoteConfigs>
77       <hudson.plugins.git.UserRemoteConfig>
78         <name>origin</name>
79         <refspec>+refs/pull/*:refs/remotes/origin/pr/*</refspec>
80         <url>git@github.com:example-org/releng/ciman</url>
81         <credentialsId>test-credential</credentialsId>
82       </hudson.plugins.git.UserRemoteConfig>
83     </userRemoteConfigs>
84     <branches>
85       <hudson.plugins.git.BranchSpec>
86         <name>**</name>
87       </hudson.plugins.git.BranchSpec>
88     </branches>
89     <excludedUsers/>
90     <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
91     <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
92     <authorOrCommitter>false</authorOrCommitter>
93     <wipeOutWorkspace>true</wipeOutWorkspace>
94     <pruneBranches>false</pruneBranches>
95     <remotePoll>false</remotePoll>
96     <gitTool>Default</gitTool>
97     <submoduleCfg class="list"/>
98     <relativeTargetDir/>
99     <reference/>
100     <gitConfigName/>
101     <gitConfigEmail/>
102     <skipTag>true</skipTag>
103     <scmName/>
104     <useShallowClone>false</useShallowClone>
105     <ignoreNotifyCommit>false</ignoreNotifyCommit>
106     <extensions>
107       <hudson.plugins.git.extensions.impl.SubmoduleOption>
108         <disableSubmodules>false</disableSubmodules>
109         <recursiveSubmodules>true</recursiveSubmodules>
110         <trackingSubmodules>false</trackingSubmodules>
111         <reference/>
112         <timeout>10</timeout>
113       </hudson.plugins.git.extensions.impl.SubmoduleOption>
114       <hudson.plugins.git.extensions.impl.WipeWorkspace/>
115     </extensions>
116   </scm>
117   <triggers class="vector">
118     <org.jenkinsci.plugins.ghprb.GhprbTrigger>
119       <spec/>
120       <adminlist/>
121       <allowMembersOfWhitelistedOrgsAsAdmin>false</allowMembersOfWhitelistedOrgsAsAdmin>
122       <whitelist/>
123       <orgslist/>
124       <cron/>
125       <triggerPhrase>^jjb-deploy (?!\*+$).+$</triggerPhrase>
126       <onlyTriggerPhrase>true</onlyTriggerPhrase>
127       <useGitHubHooks>true</useGitHubHooks>
128       <permitAll>true</permitAll>
129       <autoCloseFailedPullRequests>false</autoCloseFailedPullRequests>
130       <extensions>
131         <org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus>
132           <commitStatusContext>JJB Deploy Job</commitStatusContext>
133         </org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus>
134       </extensions>
135     </org.jenkinsci.plugins.ghprb.GhprbTrigger>
136   </triggers>
137   <builders>
138     <EnvInjectBuilder>
139       <info>
140         <propertiesContent>PIP_PACKAGES=jenkins-job-builder</propertiesContent>
141       </info>
142     </EnvInjectBuilder>
143     <hudson.tasks.Shell>
144       <command>#!/bin/bash
145 # SPDX-License-Identifier: EPL-1.0
146 ##############################################################################
147 # Copyright (c) 2017 The Linux Foundation and others.
148 #
149 # All rights reserved. This program and the accompanying materials
150 # are made available under the terms of the Eclipse Public License v1.0
151 # which accompanies this distribution, and is available at
152 # http://www.eclipse.org/legal/epl-v10.html
153 ##############################################################################
154 # pip install packages into a virtualenv using the first listed package as venv name
155 #
156 # PIP_PACKAGES is a space separated list of pypi packages to install. The first
157 #              listed package is used as the virtualenv directory name.
158 echo &quot;---&gt; pip-install.sh&quot;
159
160 # Ensure we fail the job if any steps fail.
161 # DO NOT set -u as virtualenv's activate script has unbound variables
162 set -e -o pipefail
163
164 # Install git-review using virtualenv to the latest version that supports
165 # --reviewers option, available through pip install. Existing minion image has a
166 # version that does not have it.
167 virtualenv &quot;/tmp/v/${PIP_PACKAGES%% *}&quot;
168 # shellcheck source=/tmp/v/venv/bin/activate disable=SC1091
169 source &quot;/tmp/v/${PIP_PACKAGES%% *}/bin/activate&quot;
170 pip install --quiet --upgrade pip
171 pip install --quiet --upgrade pipdeptree
172
173 # PIP_PACKAGES needs to be passed through as a space separated list of packages
174 # shellcheck disable=SC2086
175 pip install --upgrade $PIP_PACKAGES
176
177 echo &quot;----&gt; Pip Dependency Tree&quot;
178 pipdeptree
179 </command>
180     </hudson.tasks.Shell>
181     <org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep plugin="config-file-provider">
182       <managedFiles>
183         <org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
184           <fileId>jjbini-sandbox</fileId>
185           <targetLocation>$HOME/.config/jenkins_jobs/jenkins_jobs.ini</targetLocation>
186           <variable/>
187         </org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
188       </managedFiles>
189     </org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep>
190     <hudson.tasks.Shell>
191       <command>#!/bin/bash
192 # SPDX-License-Identifier: EPL-1.0
193 ##############################################################################
194 # Copyright (c) 2017 The Linux Foundation and others.
195 #
196 # All rights reserved. This program and the accompanying materials
197 # are made available under the terms of the Eclipse Public License v1.0
198 # which accompanies this distribution, and is available at
199 # http://www.eclipse.org/legal/epl-v10.html
200 ##############################################################################
201 # Push a job to jenkins-sandbox via Gerrit / GitHub comment
202 # Comment Pattern: jjb-deploy JOB_NAME
203 # JOB_NAME: Can also include * wildcards too. Additional parameters are ignored.
204 echo &quot;---&gt; jjb-deploy-job.sh&quot;
205
206 # Ensure we fail the job if any steps fail.
207 set -e -o pipefail
208
209 # shellcheck source=/tmp/v/jenkins-job-builder/bin/activate disable=SC1091
210 source &quot;/tmp/v/jenkins-job-builder/bin/activate&quot;
211
212 echo &quot;-----&gt; Fetching project&quot;
213 git fetch origin &quot;$GERRIT_REFSPEC&quot; &amp;&amp; git checkout FETCH_HEAD
214
215 # If not Gerrit Trigger than assume GitHub
216 COMMENT=&quot;${GERRIT_EVENT_COMMENT_TEXT:-$ghprbCommentBody}&quot;
217 JOB_NAME=$(echo &quot;$COMMENT&quot; | grep jjb-deploy | awk '{print $2}')
218
219 # Strip all * characters to prevent pushing all jobs to Jenkins
220 if [ -z &quot;${JOB_NAME//\*/}&quot; ]; then
221     echo &quot;ERROR: JOB_NAME cannot be empty or '*'.&quot;
222     exit 1
223 fi
224
225 jenkins-jobs update --recursive --workers 4 jjb/ &quot;$JOB_NAME&quot;
226 </command>
227     </hudson.tasks.Shell>
228   </builders>
229   <publishers>
230     <org.jenkinsci.plugins.postbuildscript.PostBuildScript>
231       <buildSteps>
232         <hudson.tasks.Shell>
233           <command>#!/bin/bash
234 # SPDX-License-Identifier: EPL-1.0
235 ##############################################################################
236 # Copyright (c) 2017 The Linux Foundation and others.
237 #
238 # All rights reserved. This program and the accompanying materials
239 # are made available under the terms of the Eclipse Public License v1.0
240 # which accompanies this distribution, and is available at
241 # http://www.eclipse.org/legal/epl-v10.html
242 ##############################################################################
243 echo &quot;---&gt; sysstat.sh&quot;
244 set +e  # DON'T fail build if script fails.
245
246 OS=$(facter operatingsystem)
247 case &quot;$OS&quot; in
248     Ubuntu)
249         SYSSTAT_PATH=&quot;/var/log/sysstat&quot;
250
251         # Dont run the script when systat is not enabled by default
252         if ! grep --quiet 'ENABLED=&quot;true&quot;' &quot;/etc/default/sysstat&quot;; then
253             exit 0
254         fi
255     ;;
256     CentOS|RedHat)
257         SYSSTAT_PATH=&quot;/var/log/sa&quot;
258     ;;
259     *)
260         # nothing to do
261         exit 0
262     ;;
263 esac
264
265 SAR_DIR=&quot;$WORKSPACE/archives/sar-reports&quot;
266 mkdir -p &quot;$SAR_DIR&quot;
267 cp &quot;$SYSSTAT_PATH/&quot;* &quot;$_&quot;
268 # convert sar data to ascii format
269 while IFS=&quot;&quot; read -r s
270 do
271     [ -f &quot;$s&quot; ] &amp;&amp; LC_TIME=POSIX sar -A -f &quot;$s&quot; &gt; &quot;$SAR_DIR/sar${s//[!0-9]/}&quot;
272 done &lt; &lt;(find &quot;$SYSSTAT_PATH&quot; -name &quot;sa[0-9]*&quot; || true)
273
274 # DON'T fail build if script fails.
275 exit 0
276 </command>
277         </hudson.tasks.Shell>
278         <org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep plugin="config-file-provider">
279           <managedFiles>
280             <org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
281               <fileId>jenkins-log-archives-settings</fileId>
282               <targetLocation/>
283               <variable>SETTINGS_FILE</variable>
284             </org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
285           </managedFiles>
286         </org.jenkinsci.plugins.configfiles.builder.ConfigFileBuildStep>
287         <EnvInjectBuilder>
288           <info>
289             <propertiesContent>SERVER_ID=logs</propertiesContent>
290           </info>
291         </EnvInjectBuilder>
292         <hudson.tasks.Shell>
293           <command>#!/bin/bash
294 # SPDX-License-Identifier: EPL-1.0
295 ##############################################################################
296 # Copyright (c) 2017 The Linux Foundation and others.
297 #
298 # All rights reserved. This program and the accompanying materials
299 # are made available under the terms of the Eclipse Public License v1.0
300 # which accompanies this distribution, and is available at
301 # http://www.eclipse.org/legal/epl-v10.html
302 ##############################################################################
303 echo &quot;---&gt; create-netrc.sh&quot;
304
305 # Ensure we fail the job if any steps fail.
306 set -eu -o pipefail
307
308 NEXUS_URL=&quot;${NEXUSPROXY:-$NEXUS_URL}&quot;
309 CREDENTIAL=$(xmlstarlet sel -N &quot;x=http://maven.apache.org/SETTINGS/1.0.0&quot; \
310     -t -m &quot;/x:settings/x:servers/x:server[x:id='${SERVER_ID}']&quot; \
311     -v x:username -o &quot;:&quot; -v x:password \
312     &quot;$SETTINGS_FILE&quot;)
313
314 machine=$(echo &quot;$NEXUS_URL&quot; | awk -F/ '{print $3}')
315 user=$(echo &quot;$CREDENTIAL&quot; | cut -f1 -d:)
316 pass=$(echo &quot;$CREDENTIAL&quot; | cut -f2 -d:)
317
318 echo &quot;machine ${machine%:*} login $user password $pass&quot; &gt; ~/.netrc
319 </command>
320         </hudson.tasks.Shell>
321         <hudson.tasks.Shell>
322           <command>#!/bin/bash
323 # SPDX-License-Identifier: EPL-1.0
324 ##############################################################################
325 # Copyright (c) 2017 The Linux Foundation and others.
326 #
327 # All rights reserved. This program and the accompanying materials
328 # are made available under the terms of the Eclipse Public License v1.0
329 # which accompanies this distribution, and is available at
330 # http://www.eclipse.org/legal/epl-v10.html
331 ##############################################################################
332 echo &quot;---&gt; lftools-install.sh&quot;
333
334 # Script to install lftools via a version passed in via lf-infra-parameters
335 #
336 # Required parameters:
337 #
338 #     LFTOOLS_VERSION: Passed in via lf-infra-parameters configuration. Can be
339 #                      set to a strict version number like '1.2.3' or using
340 #                      PEP-440 definitions.
341 #
342 #                      Examples:
343 #                          &lt;1.0.0
344 #                          &gt;=1.0.0,&lt;2.0.0
345 #
346 # By default a released version of lftools should always be used.
347 # The purpose of the 2 variables below is so that lftools devs can test
348 # unreleased versions of lftools. There are 2 methods to install a dev version
349 # of lftools:
350 #
351 #     1) gerrit patch: Used to test a patch that has not yet been merged.
352 #                      To do this set something like this:
353 #                          LFTOOLS_MODE=gerrit
354 #                          LFTOOLS_REFSPEC=refs/changes/96/5296/7
355 #
356 #     2) git branch: Used to install an lftools version from a specific branch.
357 #                    To use this set the variables as follows:
358 #                          LFTOOLS_MODE=git
359 #                          LFTOOLS_REFSPEC=master
360 #
361 #     3) release : The intended use case and default setting.
362 #                  Set LFTOOLS_MODE=release, in this case LFTOOLS_REFSPEC is unused.
363
364 LFTOOLS_MODE=release  # release | git | gerrit
365 LFTOOLS_REFSPEC=master
366
367 # Ensure we fail the job if any steps fail.
368 # DO NOT set -u as virtualenv's activate script has unbound variables
369 set -e -o pipefail
370
371 virtualenv --quiet &quot;/tmp/v/lftools&quot;
372 # shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
373 source &quot;/tmp/v/lftools/bin/activate&quot;
374 pip install --quiet --upgrade pip
375
376 case $LFTOOLS_MODE in
377     gerrit)
378         git clone https://gerrit.linuxfoundation.org/infra/releng/lftools.git /tmp/lftools
379         pushd /tmp/lftools
380         git fetch origin &quot;$LFTOOLS_REFSPEC&quot;
381         git checkout FETCH_HEAD
382         pip install --quiet --upgrade -r requirements.txt
383         pip install --quiet --upgrade -e .
384         popd
385         ;;
386
387     git)
388         pip install --quiet --upgrade git+https://gerrit.linuxfoundation.org/infra/releng/lftools.git@&quot;$BRANCH&quot;
389         ;;
390
391     release)
392         if [[ $LFTOOLS_VERSION =~ ^[0-9] ]]; then
393             LFTOOLS_VERSION=&quot;==$LFTOOLS_VERSION&quot;
394         fi
395
396         pip install --quiet --upgrade &quot;lftools${LFTOOLS_VERSION}&quot;
397         ;;
398 esac
399
400 lftools --version
401
402 # pipdeptree prints out a lot of information because lftools pulls in many
403 # dependencies. Let's only print it if we want to debug.
404 # echo &quot;----&gt; Pip Dependency Tree&quot;
405 # pip install --quiet --upgrade pipdeptree
406 # pipdeptree
407
408 #!/bin/bash
409 # SPDX-License-Identifier: EPL-1.0
410 ##############################################################################
411 # Copyright (c) 2017 The Linux Foundation and others.
412 #
413 # All rights reserved. This program and the accompanying materials
414 # are made available under the terms of the Eclipse Public License v1.0
415 # which accompanies this distribution, and is available at
416 # http://www.eclipse.org/legal/epl-v10.html
417 ##############################################################################
418 echo &quot;---&gt; logs-deploy.sh&quot;
419
420 # Ensure we fail the job if any steps fail.
421 set -eu -o pipefail
422
423 set -x  # Trace commands for this script to make debugging easier.
424
425 ARCHIVE_ARTIFACTS=&quot;${ARCHIVE_ARTIFACTS:-}&quot;
426 LOGS_SERVER=&quot;${LOGS_SERVER:-None}&quot;
427
428 if [ &quot;${LOGS_SERVER}&quot; == 'None' ]
429 then
430     set +x # Disable trace since we no longer need it
431
432     echo &quot;WARNING: Logging server not set&quot;
433 else
434     NEXUS_URL=&quot;${NEXUSPROXY:-$NEXUS_URL}&quot;
435     NEXUS_PATH=&quot;${SILO}/${JENKINS_HOSTNAME}/${JOB_NAME}/${BUILD_NUMBER}&quot;
436     BUILD_URL=&quot;${BUILD_URL}&quot;
437
438     lftools deploy archives -p &quot;$ARCHIVE_ARTIFACTS&quot; &quot;$NEXUS_URL&quot; &quot;$NEXUS_PATH&quot; &quot;$WORKSPACE&quot;
439     lftools deploy logs &quot;$NEXUS_URL&quot; &quot;$NEXUS_PATH&quot; &quot;$BUILD_URL&quot;
440
441     set +x  # Disable trace since we no longer need it.
442
443     echo &quot;Build logs: &lt;a href=\&quot;$LOGS_SERVER/$NEXUS_PATH\&quot;&gt;$LOGS_SERVER/$NEXUS_PATH&lt;/a&gt;&quot;
444 fi
445 </command>
446         </hudson.tasks.Shell>
447         <hudson.tasks.Shell>
448           <command>#!/bin/bash
449 # SPDX-License-Identifier: EPL-1.0
450 ##############################################################################
451 # Copyright (c) 2017 The Linux Foundation and others.
452 #
453 # All rights reserved. This program and the accompanying materials
454 # are made available under the terms of the Eclipse Public License v1.0
455 # which accompanies this distribution, and is available at
456 # http://www.eclipse.org/legal/epl-v10.html
457 ##############################################################################
458
459 # Clear log credential files
460 rm &quot;$SETTINGS_FILE&quot;
461 rm ~/.netrc
462 </command>
463         </hudson.tasks.Shell>
464         <hudson.plugins.descriptionsetter.DescriptionSetterBuilder>
465           <regexp>^Build logs: .*</regexp>
466         </hudson.plugins.descriptionsetter.DescriptionSetterBuilder>
467       </buildSteps>
468       <scriptOnlyIfSuccess>false</scriptOnlyIfSuccess>
469       <scriptOnlyIfFailure>false</scriptOnlyIfFailure>
470       <markBuildUnstable>false</markBuildUnstable>
471     </org.jenkinsci.plugins.postbuildscript.PostBuildScript>
472     <hudson.plugins.ws__cleanup.WsCleanup plugin="ws-cleanup">
473       <patterns>
474         <hudson.plugins.ws__cleanup.Pattern>
475           <pattern>**/*.jenkins-trigger</pattern>
476           <type>EXCLUDE</type>
477         </hudson.plugins.ws__cleanup.Pattern>
478       </patterns>
479       <deleteDirs>false</deleteDirs>
480       <cleanupMatrixParent>false</cleanupMatrixParent>
481       <externalDelete/>
482       <cleanWhenSuccess>true</cleanWhenSuccess>
483       <cleanWhenUnstable>true</cleanWhenUnstable>
484       <cleanWhenFailure>true</cleanWhenFailure>
485       <cleanWhenNotBuilt>true</cleanWhenNotBuilt>
486       <cleanWhenAborted>true</cleanWhenAborted>
487       <notFailBuild>true</notFailBuild>
488     </hudson.plugins.ws__cleanup.WsCleanup>
489   </publishers>
490   <buildWrappers>
491     <com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper/>
492     <hudson.plugins.build__timeout.BuildTimeoutWrapper>
493       <timeoutMinutes>5</timeoutMinutes>
494       <timeoutEnvVar>BUILD_TIMEOUT</timeoutEnvVar>
495       <failBuild>true</failBuild>
496       <writingDescription>false</writingDescription>
497       <timeoutPercentage>0</timeoutPercentage>
498       <timeoutMinutesElasticDefault>3</timeoutMinutesElasticDefault>
499       <timeoutType>absolute</timeoutType>
500     </hudson.plugins.build__timeout.BuildTimeoutWrapper>
501     <hudson.plugins.timestamper.TimestamperBuildWrapper/>
502     <com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
503       <user>test-credential</user>
504     </com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper>
505     <jenkins.plugins.openstack.compute.JCloudsOneOffSlave/>
506   </buildWrappers>
507 </project>