Merge "Add maven-deploy-file builder for packaging jobs"
[releng/global-jjb.git] / jjb / lf-macros.yaml
index dcd79d3..cb37429 100644 (file)
@@ -1,5 +1,8 @@
 ---
-# BUILDERS
+############
+# BUILDERS #
+############
+
 - builder:
     name: lf-infra-create-netrc
     # Macro to create a ~/.netrc file from a Maven settings.xml
           properties-content: 'SERVER_ID={server-id}'
       - shell: !include-raw-escape: ../shell/create-netrc.sh
 
+- builder:
+    name: lf-infra-docker-login
+    # Login into a custom hosted docker registry and / or docker.io
+    #
+    # The Jenkins system should have the following global variables defined
+    #
+    # DOCKER_REGISTRY : Optional
+    #                   The DNS address of the registry (IP or FQDN)
+    #                   ex: nexus3.example.com
+    #
+    # REGISTRY_PORTS  : Required if DOCKER_REGISTRY is set
+    #                   Space separated listing of the registry ports to login
+    #                   to
+    #                   ex: 10001 10002 10003 10004
+    #
+    # DOCKERHUB_EMAIL : Optional
+    #                   If this variable is set then an attempt to login to
+    #                   DockerHub (docker.io) will be also made. It should be
+    #                   set to the email address for the credentials that will
+    #                   get looked up. Only _one_ credential will ever be found
+    #                   in the maven settings file for DockerHub
+    builders:
+      - lf-provide-maven-settings:
+          global-settings-file: '{global-settings-file}'
+          settings-file: '{settings-file}'
+      - shell: !include-raw-escape: ../shell/docker-login.sh
+      - lf-provide-maven-settings-cleanup
+
 - builder:
     name: lf-infra-gpg-verify-git-signature
     # Verify gpg signature of the latest commit message in $WORKSPACE
     builders:
       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
 
-# call maven-target builder with a goal of --version to force Jenkins to
-# install the needed maven version
+- builder:
+    name: lf-infra-deploy-maven-file
+    # Deploy files to a repository.
+    #
+    # The builder requires passing the following parameters
+    # REPO_ID:           Repository ID
+    # GROUP_ID:          Group ID of the repository
+    # UPLOAD_FILES_PATH: Path to directory containing one or more files
+    builders:
+      - lf-maven-install:
+          mvn-version: '{mvn-version}'
+      - lf-provide-maven-settings:
+          global-settings-file: '{global-settings-file}'
+          settings-file: '{settings-file}'
+      - inject:
+          properties-content: |
+              REPO_ID={repo-id}
+              GROUP_ID={group-id}
+              UPLOAD_FILES_PATH={files-dir}
+      - shell: !include-raw-escape:
+          - ../shell/lftools-install.sh
+          - ../shell/deploy-maven-file.sh
+      - lf-provide-maven-settings-cleanup
+
 - builder:
     name: lf-maven-install
+    # call maven-target builder with a goal of --version to force Jenkins to
+    # install the needed maven version
     builders:
       # Create a $HOME/.wgetrc to make the Maven download quiet.
       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
       - maven-target:
-          maven-version: '{maven-version}'
+          maven-version: '{mvn-version}'
           goals: '--version'
       - shell: 'rm "$HOME/.wgetrc"'
 
-# Push a global settings and user settings maven files
 - builder:
     name: lf-provide-maven-settings
+    # Push a global settings and user settings maven files
     builders:
       - config-file-provider:
           files:
             - file-id: '{settings-file}'
               variable: 'SETTINGS_FILE'
 
+- builder:
+    name: lf-provide-maven-settings-cleanup
+    # Clear maven settings files after we are done using them
+    builders:
+      - shell: |
+          #!/bin/bash
+          set +e  # DO NOT cause build failure if any of the rm calls fail.
+
+          rm "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
+
+          # In some cases we use the lf-provide-maven-settings macro to produce
+          # a "$HOME/.netrc" file containing credentials. Remove that file here
+          # too if it exists.
+          rm "$HOME/.netrc"
+
+          # DO NOT fail build if any of the above lines fail.
+          exit 0
+
+##############
+# PARAMETERS #
+##############
 
-# PARAMETERS
-# Standard parameters used in the LF CI environments. Gerrit variables are not
-# used by GitHub projects, but defining them isn't harmful
 - parameter:
     name: lf-infra-parameters
+    # Standard parameters used in the LF CI environments. Gerrit variables are
+    # not used by GitHub projects, but defining them isn't harmful.
     parameters:
       - string:
           name: PROJECT
               Parameter to identify a Gerrit project. This is typically the
               project repo path as exists in Gerrit.
               For example: ofextensions/circuitsw
-
-              (Deprecated) Please use GERRIT_PROJECT instead. A future version
-              of global-jjb will remove this variable.
       - string:
           name: GERRIT_PROJECT
           default: '{project}'
               Note that Gerrit will override this parameter automatically if a
               job is triggered by Gerrit.
 
-# Useful parameters when working with TOX
-# https://tox.readthedocs.io/
+- parameter:
+    name: lf-infra-maven-parameters
+    parameters:
+      - string:
+          name: MAVEN_OPTS
+          default: '{mvn-opts}'
+          description: |
+              Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
+      - string:
+          name: MAVEN_PARAMS
+          default: '{mvn-params}'
+          description: |
+              Maven parameters to pass to the mvn command.
+      - string:
+          name: MVN
+          # Sets an env var for shell scripts to be able to call the dynamically
+          # installed maven without having to calculate the path themselves.
+          default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn'
+          description: 'Maven selector to be used by shell scripts'
+      - string:
+          name: STAGING_PROFILE_ID
+          default: '{staging-profile-id}'
+          description: |
+              Nexus staging profile ID.
+
 - parameter:
     name: lf-infra-tox-parameters
+    # Useful parameters when working with TOX
+    # https://tox.readthedocs.io/
     parameters:
       - string:
           name: TOX_DIR
               Tox environments to run build against.
               Example: docs,py2,py3
 
-# Set an env var for shell scripts to be able to call the dynamically installed
-# maven without having to calculate the path themselves
-- parameter:
-    name: lf-maven-exec
-    parameters:
-      - string:
-          name: MVN
-          # yamllint disable-line rule:line-length
-          default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{maven-version}/bin/mvn'
-          description: 'Maven selector to be used by shell scripts'
-
+##############
+# PROPERTIES #
+##############
 
-# PROPERTIES
 - property:
     name: lf-infra-properties
     properties:
           # Do not allow artifacts to be stored in Jenkins.
           artifact-num-to-keep: 0
 
-# PUBLISHERS
+##############
+# PUBLISHERS #
+##############
+
 - publisher:
     name: lf-infra-publish
     # lf-infra macro to finish up a build.
             - '**/*.jenkins-trigger'
           fail-build: false
 
-# SCM
+#######
+# SCM #
+#######
+
 - scm:
     name: lf-infra-gerrit-scm
     scm:
             recursive: '{submodule-recursive}'
           choosing-strategy: '{choosing-strategy}'
 
-# WRAPPERS
+############
+# WRAPPERS #
+############
+
 - wrapper:
     name: lf-infra-wrappers
     wrappers: