Allow git-url to be overridden by job
[releng/global-jjb.git] / jjb / lf-macros.yaml
1 ---
2 # BUILDERS
3 - builder:
4     name: lf-infra-create-netrc
5     # Macro to create a ~/.netrc file from a Maven settings.xml
6     # Parameters:
7     #     {server-id} The id of a server as defined in settings.xml
8     builders:
9       - inject:
10           properties-content: 'SERVER_ID={server-id}'
11       - shell: !include-raw-escape: ../shell/create-netrc.sh
12
13 - builder:
14     name: lf-infra-gpg-verify-git-signature
15     # Verify gpg signature of the latest commit message in $WORKSPACE
16     #
17     # This command assumes that $WORKSPACE is a git repo.
18     #
19     # TODO: Verify signature after downloading users public key from a locally
20     # created repository instead of the public keymesh. This requires a process
21     # in place to get ODL developers public keys into a local repository without
22     # increasing the job thoughput.
23     builders:
24       - shell: !include-raw: ../shell/gpg-verify-git-signature.sh
25
26 - builder:
27     name: lf-infra-ship-logs
28     builders:
29       - config-file-provider:
30           files:
31             - file-id: 'jenkins-log-archives-settings'
32               variable: 'SETTINGS_FILE'
33       - lf-infra-create-netrc:
34           server-id: logs
35       - shell: !include-raw:
36           - ../shell/lftools-install.sh
37           - ../shell/logs-deploy.sh
38       - shell: !include-raw:
39           - ../shell/logs-clear-credentials.sh
40       - description-setter:
41           regexp: '^Build logs: .*'
42
43 - builder:
44     name: lf-jacoco-nojava-workaround
45     builders:
46       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
47
48 # call maven-target builder with a goal of --version to force Jenkins to
49 # install the needed maven version
50 - builder:
51     name: lf-maven-install
52     builders:
53       - maven-target:
54           maven-version: '{maven-version}'
55           goals: '--version'
56
57 # Push a global settings and user settings maven files
58 - builder:
59     name: lf-provide-maven-settings
60     builders:
61       - config-file-provider:
62           files:
63             - file-id: '{global-settings-file}'
64               variable: 'GLOBAL_SETTINGS_FILE'
65             - file-id: '{settings-file}'
66               variable: 'SETTINGS_FILE'
67
68
69 # PARAMETERS
70 # Standard parameters used in the LF CI environments. Gerrit variables are not
71 # used by GitHub projects, but defining them isn't harmful
72 - parameter:
73     name: lf-infra-parameters
74     parameters:
75       - string:
76           name: PROJECT
77           default: '{project}'
78           description: |
79               Parameter to identify a Gerrit project. This is typically the
80               project repo path as exists in Gerrit.
81               For example: ofextensions/circuitsw
82
83               (Deprecated) Please use GERRIT_PROJECT instead. A future version
84               of global-jjb will remove this variable.
85       - string:
86           name: GERRIT_PROJECT
87           default: '{project}'
88           description: |
89               Parameter to identify Gerrit project. This is typically the
90               project repo path as exists in Gerrit.
91               For example: ofextensions/circuitsw
92
93               Note that Gerrit will override this parameter automatically if a
94               job is triggered by Gerrit.
95       - string:
96           name: GERRIT_BRANCH
97           default: '{branch}'
98           description: |
99               Parameter to identify a Gerrit branch.
100
101               Note that Gerrit will override this parameter automatically if a
102               job is triggered by Gerrit.
103       - string:
104           name: GERRIT_REFSPEC
105           default: ''
106           description: |
107               Parameter to identify a refspec when pulling from Gerrit.
108
109               Note that Gerrit will override this parameter automatically if a
110               job is triggered by Gerrit.
111
112 # Set an env var for shell scripts to be able to call the dynamically installed
113 # maven without having to calculate the path themselves
114 - parameter:
115     name: lf-maven-exec
116     parameters:
117       - string:
118           name: MVN
119           # yamllint disable-line rule:line-length
120           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{maven-version}/bin/mvn'
121           description: 'Maven selector to be used by shell scripts'
122
123
124 # PROPERTIES
125 - property:
126     name: lf-infra-properties
127     properties:
128       - build-discarder:
129           # Allow build data to be stored at a length configured by the
130           # downstream project.
131           days-to-keep: '{build-days-to-keep}'
132           # Do not allow artifacts to be stored in Jenkins.
133           artifact-num-to-keep: 0
134
135 # PUBLISHERS
136 - publisher:
137     name: lf-infra-publish
138     # lf-infra macro to finish up a build.
139     #
140     # Handles the following:
141     #   - Shipping logs to Nexus logs site repository
142     #   - Cleanup workspace
143     publishers:
144       - postbuildscript:
145           builders:
146             - lf-infra-ship-logs
147           script-only-if-succeeded: false
148           script-only-if-failed: false
149           mark-unstable-if-failed: false
150       - workspace-cleanup:
151           exclude:
152             # Do not clean up *.jenkins-trigger files for jobs that use a
153             # properties file as input for triggering another build.
154             - '**/*.jenkins-trigger'
155           fail-build: false
156
157 # SCM
158 - scm:
159     name: lf-infra-gerrit-scm
160     scm:
161       - git:
162           credentials-id: '{jenkins-ssh-credential}'
163           url: '{git-url}'
164           refspec: '{refspec}'
165           branches:
166             - 'refs/heads/{branch}'
167           skip-tag: true
168           wipe-workspace: true
169           submodule:
170             recursive: '{submodule-recursive}'
171           choosing-strategy: '{choosing-strategy}'
172
173 - scm:
174     name: lf-infra-github-scm
175     scm:
176       - git:
177           credentials-id: '{jenkins-ssh-credential}'
178           url: '{url}'
179           refspec: '{refspec}'
180           skip-tag: true
181           wipe-workspace: true
182           submodule:
183             recursive: '{submodule-recursive}'
184           choosing-strategy: '{choosing-strategy}'
185
186 # WRAPPERS
187 - wrapper:
188     name: lf-infra-wrappers
189     wrappers:
190       - mask-passwords
191       - timeout:
192           type: absolute
193           timeout: '{build-timeout}'
194           timeout-var: 'BUILD_TIMEOUT'
195           fail: true
196       - timestamps
197       - ssh-agent-credentials:
198           users:
199             - '{jenkins-ssh-credential}'
200       - openstack:
201           single-use: true