---
-# BUILDERS
+############
+# BUILDERS #
+############
+
- builder:
name: lf-infra-create-netrc
# Macro to create a ~/.netrc file from a Maven settings.xml
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-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:
variable: 'GLOBAL_SETTINGS_FILE'
- 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:
--- /dev/null
+---
+# This file contains job templates for Maven projects.
+
+- job-group:
+ name: '{project-name}-maven-jobs'
+
+ # This job group contains all the recommended jobs that should be deployed
+ # for any project ci.
+
+ jobs:
+ - gerrit-maven-release
+
+- job-group:
+ name: '{project-name}-github-maven-jobs'
+
+ # This job group contains all the recommended jobs that should be deployed
+ # for any project ci that is using github.
+
+ jobs:
+ - github-maven-release
+
+####################
+# Anchors & Macros #
+####################
+- lf_maven_release: &lf_maven_release
+ name: lf-maven-release
+
+ # Produces a release candidate by creating a staging repo in Nexus.
+ #
+ # Runs a Maven build and deploys to $WORKSPACE/m2repo directory. This
+ # directory can then be reused later to deploy to Nexus.
+ #
+ # Required parameters:
+ # build-node: The node to run build on.
+ # jenkins-ssh-credential: Credential to use for SSH. (Generally should
+ # be configured in defaults.yaml)
+ # settings-file: The name of settings file containing credentials for
+ # the project.
+ # global-settings-file: The name of the Maven global settings to use for
+ # Maven configuration.
+ # staging-profile-id: Profile ID of the project's Nexus staging profile.
+
+ project-type: freestyle
+ node: '{build-node}'
+ jdk: '{java-version}'
+
+ ######################
+ # Default parameters #
+ ######################
+
+ branch: master
+ build-timeout: 30
+ git-url: '$GIT_URL/$PROJECT'
+ global-settings-file: global-settings
+ java-version: openjdk8
+ mvn-opts: ''
+ mvn-params: ''
+ mvn-version: mvn33
+ submodule-recursive: true
+
+ #####################
+ # Job Configuration #
+ #####################
+
+ properties:
+ - lf-infra-properties:
+ # Keep around for 30 days in case a release takes long to get approved.
+ build-days-to-keep: 30
+
+ parameters:
+ - lf-infra-parameters:
+ project: '{project}'
+ branch: '{branch}'
+ - lf-infra-maven-parameters:
+ mvn-opts: '{mvn-opts}'
+ mvn-params: '{mvn-params}'
+ mvn-version: '{mvn-version}'
+ staging-profile-id: '{staging-profile-id}'
+
+ wrappers:
+ - lf-infra-wrappers:
+ build-timeout: '{build-timeout}'
+ jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+ builders:
+ - lf-jacoco-nojava-workaround
+ - lf-maven-install:
+ mvn-version: '{mvn-version}'
+ - lf-provide-maven-settings:
+ global-settings-file: '{global-settings-file}'
+ settings-file: '{settings-file}'
+ - lf-infra-create-netrc:
+ server-id: opendaylight-staging
+ - shell: !include-raw-escape:
+ - ../shell/lftools-install.sh
+ - ../shell/common-variables.sh
+ - ../shell/maven-patch-release.sh
+ - ../shell/maven-build.sh
+ - ../shell/maven-stage.sh
+ - lf-provide-maven-settings-cleanup
+
+ publishers:
+ # TODO: Make email notification work.
+ # - lf-infra-email-notify:
+ # email-recipients: '{email-recipients}'
+ # email-prefix: '[releng]'
+ - lf-infra-publish
+
+
+#################
+# Job Templates #
+#################
+
+- job-template:
+ name: '{project-name}-maven-release-{stream}'
+ id: gerrit-maven-release
+ <<: *lf_maven_release
+
+ scm:
+ - lf-infra-gerrit-scm:
+ jenkins-ssh-credential: '{jenkins-ssh-credential}'
+ git-url: '{git-url}'
+ refspec: '$GERRIT_REFSPEC'
+ branch: '$GERRIT_BRANCH'
+ submodule-recursive: '{submodule-recursive}'
+ choosing-strategy: gerrit
+
+- job-template:
+ name: '{project-name}-maven-release-{stream}'
+ id: github-maven-release
+ <<: *lf_maven_release
+
+ properties:
+ - github:
+ url: '${{GIT_URL}}{github-org}/{project}'
+
+ scm:
+ - lf-infra-github-scm:
+ url: '${{GIT_CLONE_URL}}{github-org}/{project}'
+ refspec: '+refs/pull/*:refs/remotes/origin/pr/*'
+ branch: '{branch}'
+ submodule-recursive: '{submodule-recursive}'
+ choosing-strategy: default
+ jenkins-ssh-credential: '{jenkins-ssh-credential}'
--- /dev/null
+#!/bin/bash
+# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+# This file contains a list of variables that are generally useful in many
+# scripts. It is meant to be sourced in other scripts so that the variables can
+# be called.
+
+MAVEN_OPTIONS="$(echo --show-version \
+ --batch-mode \
+ -Djenkins \
+ -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
+ -Dmaven.repo.local=/tmp/r \
+ -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r)"
+echo "$MAVEN_OPTIONS"
--- /dev/null
+#!/bin/bash
+# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+# This script builds a Maven project and deploys it into a staging repo which
+# can be used to deploy elsewhere later eg. Nexus staging / snapshot repos.
+
+# DO NOT enable -u because $MAVEN_PARAMS and $MAVEN_OPTIONS could be unbound.
+# Ensure we fail the job if any steps fail.
+set -e -o pipefail
+set +u
+
+export MAVEN_OPTS
+
+# Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters.
+# shellcheck disable=SC2086
+$MVN clean deploy \
+ --global-settings "$GLOBAL_SETTINGS_FILE" \
+ --settings "$SETTINGS_FILE" \
+ -DaltDeploymentRepository=staging::default::file:"$WORKSPACE"/m2repo \
+ $MAVEN_PARAMS $MAVEN_OPTIONS
--- /dev/null
+#!/bin/bash
+# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+# This script removes the -SNAPSHOT from a project to prepare it for release.
+
+PATCH_DIR="$WORKSPACE/archives/patches"
+mkdir -p "$PATCH_DIR"
+
+# Ensure we fail the job if any steps fail.
+set -eu -o pipefail
+
+echo "$PROJECT" "$(git rev-parse --verify HEAD)" | tee -a "$PATCH_DIR/taglist.log"
+
+# Strip -SNAPSHOT from version to prepare release.
+find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g'
+
+git commit -am "Release $PROJECT"
+git format-patch --stdout "origin/$GERRIT_BRANCH" > "$PATCH_DIR/${PROJECT//\//-}.patch"
+git bundle create "$PATCH_DIR/${PROJECT//\//-}.bundle" "origin/${GERRIT_BRANCH}..HEAD"
--- /dev/null
+#!/bin/bash
+# @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+# This script publishes artifacts to a staging repo in Nexus.
+#
+# $WORKSPACE/m2repo : Exists and used to deploy the staging repository.
+# $NEXUS_URL : Jenkins global variable should be defined.
+# $STAGING_PROFILE_ID : Provided by a job parameter.
+
+# Ensure we fail the job if any steps fail.
+set -eu -o pipefail
+
+TMP_FILE="$(mktemp)"
+lftools deploy nexus-stage "$NEXUS_URL" "$STAGING_PROFILE_ID" "$WORKSPACE/m2repo" | tee "$TMP_FILE"
+staging_repo=$(sed -n -e 's/Staging repository \(.*\) created\./\1/p' "$TMP_FILE")
+
+# Store repo info to a file in archives
+mkdir -p "$WORKSPACE/archives"
+echo "$staging_repo" > "$WORSPACE/archives/staging-repo.txt"
+
+# Cleanup
+rm "$TMP_FILE"