From: Thanh Ha Date: Fri, 13 Oct 2017 03:34:15 +0000 (-0400) Subject: Add Maven job to build dependencies with patches X-Git-Tag: v0.10.0~1^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=8c159f91ad6c28b20fc1cf271915380d83ad2f80;p=releng%2Fglobal-jjb.git Add Maven job to build dependencies with patches Provide a Maven job that can verify a patch including firstly building projects it depends on with their patches first. This allows projects to validate a patch that has upstream project dependencies which need to be merged first. Requires a new global variable to be defined in Jenkins GERRIT_URL containing the base path to the Gerrit Web UI. Issue: RELENG-526 Change-Id: Ie9ccb88c21ab5674d0156566da1daee4aa43d641 Signed-off-by: Thanh Ha --- diff --git a/.jjb-test/expected-xml/gerrit-maven-maven-verify-deps-master-mvn33-openjdk8 b/.jjb-test/expected-xml/gerrit-maven-maven-verify-deps-master-mvn33-openjdk8 new file mode 100644 index 00000000..8903c2bb --- /dev/null +++ b/.jjb-test/expected-xml/gerrit-maven-maven-verify-deps-master-mvn33-openjdk8 @@ -0,0 +1,740 @@ + + + openjdk8 + + <!-- Managed by Jenkins Job Builder --> + false + false + false + true + build-vm + false + + + + 7 + -1 + -1 + 0 + + + + + + PROJECT + Parameter to identify a Gerrit project. This is typically the +project repo path as exists in Gerrit. +For example: ofextensions/circuitsw + + releng/ciman + + + STREAM + Stream is often set to the same name as 'branch' but can +sometimes be used as a name representing a project's release code +name. + + master + + + GERRIT_PROJECT + Parameter to identify Gerrit project. This is typically the +project repo path as exists in Gerrit. +For example: ofextensions/circuitsw + +Note that Gerrit will override this parameter automatically if a +job is triggered by Gerrit. + + releng/ciman + + + GERRIT_BRANCH + Parameter to identify a Gerrit branch. + +Note that Gerrit will override this parameter automatically if a +job is triggered by Gerrit. + + master + + + GERRIT_REFSPEC + Parameter to identify a refspec when pulling from Gerrit. + +Note that Gerrit will override this parameter automatically if a +job is triggered by Gerrit. + + refs/heads/master + + + LFTOOLS_VERSION + Version of lftools to install. Can be a specific version like +'0.6.0' or a PEP-440 definition. +https://www.python.org/dev/peps/pep-0440/ +For example '<1.0.0' or '>=1.0.0,<2.0.0'. + + <1.0.0 + + + MAVEN_OPTS + Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m + + + + + MAVEN_PARAMS + Maven parameters to pass to the mvn command. + + -Dstream=$STREAM + + + MVN + Maven selector to be used by shell scripts + /w/tools/hudson.tasks.Maven_MavenInstallation/mvn33/bin/mvn + + + STAGING_PROFILE_ID + Nexus staging profile ID. + + uuddlrlrba + + + + + + 2 + + + origin + $GERRIT_REFSPEC + $GIT_URL/$PROJECT + test-credential + + + + + refs/heads/$GERRIT_BRANCH + + + + + false + false + true + false + false + Default + + + + + + true + + false + false + + + false + true + false + + 10 + + + + + + + + + + ANT + releng/ciman + + + ANT + **/master + + + + + ANT + ** + + + false + + + + false + false + false + false + + false + false + true + false + false + + + False + + false + + + recheck: [0-9 ]+ + + + + + + + + + + test-server + + + + + mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes + + + echo "quiet=on" > "$HOME/.wgetrc" + + + --version + + mvn33 + false + + + + + rm "$HOME/.wgetrc" + + + + + global-settings + + GLOBAL_SETTINGS_FILE + + + gerrit-maven-project-settings + + SETTINGS_FILE + + + + + #!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## +# Fetches patches all projects provided by comment trigger +# +# Takes a list of Gerrit patches and fetches all projects and cherry-pick +# patches for projects. The trigger is +# 'recheck: SPACE_SEPERATED_LIST_OF_PATCHES' +# +# NOTE: This script assumes the user will provide the correct dependency order +# via the PATCHES list. + +# Ensure we fail the job if any steps fail. +set -eu -o pipefail + +REPOS_DIR="$WORKSPACE/.repos" + +PATCHES=($(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'recheck:' | awk -F: '{print $2}')) + +projects=() +for patch in $(echo "${PATCHES[@]}"); do + json=$(curl -s "$GERRIT_URL/changes/$patch" | sed -e "s/)]}'//") + project=$(echo "$json" | jq -r '.project') + branch=$(echo "$json" | jq -r '.branch') + + if [ ! -d "$REPOS_DIR/$project" ]; then + git clone -q --depth 1 -b "$branch" "$GIT_URL/$project" "$REPOS_DIR/$project" + + # This array will be used later to determine project build order. + projects+=("$project") + fi + + pushd "$REPOS_DIR/$project" + git remote add gerrit "$GIT_URL/$project" + git review --cherrypick="$patch" + popd +done + +# This script should be a macro which re-inject's the projects variable back +# into the build so a script later on can use it. +echo "DEPENDENCY_BUILD_ORDER=${projects[*]}" > "$WORKSPACE/.dependency.properties" + + + + + $WORKSPACE/.dependency.properties + + + + #!/bin/bash +# SPDX-License-Identifier: 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" + +#!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## + +# Builds projects provided via $DEPENDENCY_BUILD_ORDER list +# +# This runs a `mvn clean install` against all projects provided by a list. This +# script is a companion script for the gerrit-fetch-dependencies script which +# clones project repos to "$WORKSPACE/.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 + +PROJECTS=($(echo "$DEPENDENCY_BUILD_ORDER")) +REPOS_DIR="$WORKSPACE/.repos" + +export MAVEN_OPTS + +for project in "${PROJECTS[@]}"; do + pushd "$REPOS_DIR/$project" + # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters. + # shellcheck disable=SC2086 + $MVN clean install \ + -Pq \ + -DskipTests=true \ + --global-settings "$GLOBAL_SETTINGS_FILE" \ + --settings "$SETTINGS_FILE" \ + $MAVEN_PARAMS $MAVEN_OPTIONS + popd +done + + + + #!/bin/bash +# SPDX-License-Identifier: 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" + +#!/bin/bash +# SPDX-License-Identifier: 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 + + + + #!/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 + + + + + + false + + + + + low + [FINDBUGS] + + false + false + false + false + + + + + + + + + + + false + true + false + + + + **/**.exec + **/classes + **/src/main/java + + + **/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/** + 10 + 20 + 50 + 40 + + + + + #!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## +echo "---> sysstat.sh" +set +e # DON'T fail build if script fails. + +OS=$(facter operatingsystem) +case "$OS" in + Ubuntu) + SYSSTAT_PATH="/var/log/sysstat" + + # Dont run the script when systat is not enabled by default + if ! grep --quiet 'ENABLED="true"' "/etc/default/sysstat"; then + exit 0 + fi + ;; + CentOS|RedHat) + SYSSTAT_PATH="/var/log/sa" + ;; + *) + # nothing to do + exit 0 + ;; +esac + +SAR_DIR="$WORKSPACE/archives/sar-reports" +mkdir -p "$SAR_DIR" +cp "$SYSSTAT_PATH/"* "$_" +# convert sar data to ascii format +while IFS="" read -r s +do + [ -f "$s" ] && LC_TIME=POSIX sar -A -f "$s" > "$SAR_DIR/sar${s//[!0-9]/}" +done < <(find "$SYSSTAT_PATH" -name "sa[0-9]*" || true) + +# DON'T fail build if script fails. +exit 0 + + + + + + jenkins-log-archives-settings + + SETTINGS_FILE + + + + + + SERVER_ID=logs + + + + #!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## +echo "---> create-netrc.sh" + +# Ensure we fail the job if any steps fail. +set -eu -o pipefail + +NEXUS_URL="${NEXUS_URL:-$NEXUSPROXY}" +CREDENTIAL=$(xmlstarlet sel -N "x=http://maven.apache.org/SETTINGS/1.0.0" \ + -t -m "/x:settings/x:servers/x:server[x:id='${SERVER_ID}']" \ + -v x:username -o ":" -v x:password \ + "$SETTINGS_FILE") + +machine=$(echo "$NEXUS_URL" | awk -F/ '{print $3}') +user=$(echo "$CREDENTIAL" | cut -f1 -d:) +pass=$(echo "$CREDENTIAL" | cut -f2 -d:) + +echo "machine $machine login $user password $pass" > ~/.netrc + + + + #!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## +echo "---> lftools-install.sh" + +# Script to install lftools via a version passed in via lf-infra-parameters +# +# Required parameters: +# +# LFTOOLS_VERSION: Passed in via lf-infra-parameters configuration. Can be +# set to a strict version number like '1.2.3' or using +# PEP-440 definitions. +# +# Examples: +# <1.0.0 +# >=1.0.0,<2.0.0 +# +# By default a released version of lftools should always be used. +# The purpose of the 2 variables below is so that lftools devs can test +# unreleased versions of lftools. There are 2 methods to install a dev version +# of lftools: +# +# 1) gerrit patch: Used to test a patch that has not yet been merged. +# To do this set something like this: +# LFTOOLS_MODE=gerrit +# LFTOOLS_REFSPEC=refs/changes/96/5296/7 +# +# 2) git branch: Used to install an lftools version from a specific branch. +# To use this set the variables as follows: +# LFTOOLS_MODE=git +# LFTOOLS_REFSPEC=master +# +# 3) release : The intended use case and default setting. +# Set LFTOOLS_MODE=release, in this case LFTOOLS_REFSPEC is unused. + +LFTOOLS_MODE=release # release | git | gerrit +LFTOOLS_REFSPEC=master + +# Ensure we fail the job if any steps fail. +# DO NOT set -u as virtualenv's activate script has unbound variables +set -e -o pipefail + +virtualenv --quiet "/tmp/v/lftools" +# shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091 +source "/tmp/v/lftools/bin/activate" +pip install --quiet --upgrade pip + +case $LFTOOLS_MODE in + gerrit) + git clone https://gerrit.linuxfoundation.org/infra/releng/lftools.git /tmp/lftools + pushd /tmp/lftools + git fetch origin "$LFTOOLS_REFSPEC" + git checkout FETCH_HEAD + pip install --quiet --upgrade -r requirements.txt + pip install --quiet --upgrade -e . + popd + ;; + + git) + pip install --quiet --upgrade git+https://gerrit.linuxfoundation.org/infra/releng/lftools.git@"$BRANCH" + ;; + + release) + if [[ $LFTOOLS_VERSION =~ ^[0-9] ]]; then + LFTOOLS_VERSION="==$LFTOOLS_VERSION" + fi + + pip install --quiet --upgrade "lftools${LFTOOLS_VERSION}" + ;; +esac + +lftools --version + +# pipdeptree prints out a lot of information because lftools pulls in many +# dependencies. Let's only print it if we want to debug. +# echo "----> Pip Dependency Tree" +# pip install --quiet --upgrade pipdeptree +# pipdeptree + +#!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## +echo "---> logs-deploy.sh" + +# Ensure we fail the job if any steps fail. +set -eu -o pipefail + +set -x # Trace commands for this script to make debugging easier. + +ARCHIVE_ARTIFACTS="${ARCHIVE_ARTIFACTS:-}" +LOGS_SERVER="${LOGS_SERVER:-None}" + +if [ "${LOGS_SERVER}" == 'None' ] +then + set +x # Disable trace since we no longer need it + + echo "WARNING: Logging server not set" +else + NEXUS_URL="${NEXUS_URL:-$NEXUSPROXY}" + NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/${JOB_NAME}/${BUILD_NUMBER}" + BUILD_URL="${BUILD_URL}" + + lftools deploy archives -p "$ARCHIVE_ARTIFACTS" "$NEXUS_URL" "$NEXUS_PATH" "$WORKSPACE" + lftools deploy logs "$NEXUS_URL" "$NEXUS_PATH" "$BUILD_URL" + + set +x # Disable trace since we no longer need it. + + echo "Build logs: <a href=\"$LOGS_SERVER/$NEXUS_PATH\">$LOGS_SERVER/$NEXUS_PATH</a>" +fi + + + + #!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## + +# Clear log credential files +rm "$SETTINGS_FILE" +rm ~/.netrc + + + + ^Build logs: .* + + + false + false + false + + + + + **/*.jenkins-trigger + EXCLUDE + + + false + false + + true + true + true + true + true + true + + + + + + 60 + BUILD_TIMEOUT + true + false + 0 + 3 + absolute + + + + test-credential + + + + diff --git a/.jjb-test/lf-maven-jobs.yaml b/.jjb-test/lf-maven-jobs.yaml index bb33d7a4..ab0e894e 100644 --- a/.jjb-test/lf-maven-jobs.yaml +++ b/.jjb-test/lf-maven-jobs.yaml @@ -8,6 +8,7 @@ - gerrit-maven-release - gerrit-maven-sonar - gerrit-maven-verify + - gerrit-maven-verify-dependencies project-name: gerrit-maven javadoc-path: org.example.project/$STREAM diff --git a/README.md b/README.md index 4e0e0478..50d9c6ef 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ be available. For example: ``` +GERRIT_URL=https://git.opendaylight.org/gerrit GIT_URL=ssh://jenkins-$SILO@git.opendaylight.org:29418 GIT_CLONE_URL=git@github.com: JENKINS_HOSTNAME=jenkins092 diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index 996ae5a4..d56b25f6 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -3,6 +3,20 @@ # BUILDERS # ############ +- builder: + name: lf-fetch-dependent-patches + # Fetches all patches provided via comment trigger + # + # This macro will fetch all patches provided via comment trigger and will + # create a list of projects from those patches via environment variable + # called DEPENDENCY_BUILD_ORDER which can be used if necessary to build + # projects in the specified order. The order is determined by first patch + # instance for a project in the patch list. + builders: + - shell: !include-raw: ../shell/gerrit-fetch-dependencies.sh + - inject: + properties-file: $WORKSPACE/.dependency.properties + - builder: name: lf-infra-create-netrc # Macro to create a ~/.netrc file from a Maven settings.xml diff --git a/jjb/lf-maven-jobs.yaml b/jjb/lf-maven-jobs.yaml index eaa4ef87..c6bfe1f1 100644 --- a/jjb/lf-maven-jobs.yaml +++ b/jjb/lf-maven-jobs.yaml @@ -11,6 +11,7 @@ - gerrit-maven-clm - gerrit-maven-release - gerrit-maven-verify + - gerrit-maven-verify-dependencies - job-group: name: '{project-name}-github-maven-jobs' @@ -905,3 +906,126 @@ - '' github_pr_admin_list: - '' + +############################# +# Maven Verify Dependencies # +############################# + +- lf_maven_verify_dependencies: &lf_maven_verify_dependencies + name: lf-maven-verify-dependencies + + # Verify job which runs mvn clean install to test a project build /w deps + # + # This job can be used to verify a patch in conjunction to all of the + # upstream patches it depends on. The user of this job can provide a list + # via comment trigger. The trigger is: + # + # 'recheck: SPACE_SEPERATED_LIST_OF_PATCHES' + # + # 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) + # :mvn-settings: The name of settings file containing credentials for + # the project. + # + # Optional parameters: + # + # :branch: Git branch to fetch for the build. (default: master) + # :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7) + # :build-timeout: Timeout in seconds before aborting build. (default: 60) + # :git-url: URL clone project from. (default: $GIT_URL/$PROJECT) + # :java-version: Version of Java to use for the build. (default: openjdk8) + # :mvn-global-settings: The name of the Maven global settings to use for + # Maven configuration. (default: global-settings) + # :mvn-opts: Sets MAVEN_OPTS. (default: '') + # :mvn-params: Additional mvn parameters to pass to the cli. (default: '') + # :mvn-version: Version of maven to use. (default: mvn33) + # :stream: Keyword that can be used to represent a release code-name. + # Often the same as the branch. (default: master) + # :submodule-recursive: Whether to checkout submodules recursively. + # (default: true) + # + # :gerrit_verify_triggers: Override Gerrit Triggers. + # :gerrit_trigger_file_paths: Override file paths which can be used to + # filter which file modifications will trigger a build. + + ###################### + # Default parameters # + ###################### + + branch: master + build-days-to-keep: 7 + build-timeout: 60 + git-url: '$GIT_URL/$PROJECT' + java-version: openjdk8 + mvn-global-settings: global-settings + mvn-opts: '' + mvn-params: '-Dstream=$STREAM' + mvn-version: mvn33 + staging-profile-id: '' # Unused by this job + stream: master + submodule-recursive: true + + gerrit_verify_triggers: + - comment-added-contains-event: + comment-contains-value: 'recheck: [0-9 ]+' + gerrit_trigger_file_paths: + - compare-type: ANT + pattern: '**' + + ##################### + # Job Configuration # + ##################### + + concurrent: true + + builders: + - lf-jacoco-nojava-workaround + - lf-maven-install: + mvn-version: '{mvn-version}' + - lf-provide-maven-settings: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + - lf-fetch-dependent-patches + - shell: !include-raw-escape: + - ../shell/common-variables.sh + - ../shell/maven-build-deps.sh + - shell: !include-raw-escape: + - ../shell/common-variables.sh + - ../shell/maven-build.sh + - lf-provide-maven-settings-cleanup + + publishers: + - findbugs + - lf-jacoco-report + - lf-infra-publish + +- job-template: + name: '{project-name}-maven-verify-deps-{stream}-{mvn-version}-{java-version}' + id: gerrit-maven-verify-dependencies + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_verify_dependencies + + 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 + + triggers: + - gerrit: + server-name: '{gerrit-server-name}' + trigger-on: '{obj:gerrit_verify_triggers}' + projects: + - project-compare-type: ANT + project-pattern: '{project}' + branches: + - branch-compare-type: ANT + branch-pattern: '**/{branch}' + file-paths: '{obj:gerrit_trigger_file_paths}' diff --git a/shell/gerrit-fetch-dependencies.sh b/shell/gerrit-fetch-dependencies.sh new file mode 100644 index 00000000..4870b10e --- /dev/null +++ b/shell/gerrit-fetch-dependencies.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## +# Fetches patches all projects provided by comment trigger +# +# Takes a list of Gerrit patches and fetches all projects and cherry-pick +# patches for projects. The trigger is +# 'recheck: SPACE_SEPERATED_LIST_OF_PATCHES' +# +# NOTE: This script assumes the user will provide the correct dependency order +# via the PATCHES list. + +# Ensure we fail the job if any steps fail. +set -eu -o pipefail + +REPOS_DIR="$WORKSPACE/.repos" + +PATCHES=($(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep 'recheck:' | awk -F: '{print $2}')) + +projects=() +for patch in $(echo "${PATCHES[@]}"); do + json=$(curl -s "$GERRIT_URL/changes/$patch" | sed -e "s/)]}'//") + project=$(echo "$json" | jq -r '.project') + branch=$(echo "$json" | jq -r '.branch') + + if [ ! -d "$REPOS_DIR/$project" ]; then + git clone -q --depth 1 -b "$branch" "$GIT_URL/$project" "$REPOS_DIR/$project" + + # This array will be used later to determine project build order. + projects+=("$project") + fi + + pushd "$REPOS_DIR/$project" + git remote add gerrit "$GIT_URL/$project" + git review --cherrypick="$patch" + popd +done + +# This script should be a macro which re-inject's the projects variable back +# into the build so a script later on can use it. +echo "DEPENDENCY_BUILD_ORDER=${projects[*]}" > "$WORKSPACE/.dependency.properties" diff --git a/shell/maven-build-deps.sh b/shell/maven-build-deps.sh new file mode 100644 index 00000000..fdb29b2b --- /dev/null +++ b/shell/maven-build-deps.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# SPDX-License-Identifier: 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 +############################################################################## + +# Builds projects provided via $DEPENDENCY_BUILD_ORDER list +# +# This runs a `mvn clean install` against all projects provided by a list. This +# script is a companion script for the gerrit-fetch-dependencies script which +# clones project repos to "$WORKSPACE/.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 + +PROJECTS=($(echo "$DEPENDENCY_BUILD_ORDER")) +REPOS_DIR="$WORKSPACE/.repos" + +export MAVEN_OPTS + +for project in "${PROJECTS[@]}"; do + pushd "$REPOS_DIR/$project" + # Disable SC2086 because we want to allow word splitting for $MAVEN_* parameters. + # shellcheck disable=SC2086 + $MVN clean install \ + -Pq \ + -DskipTests=true \ + --global-settings "$GLOBAL_SETTINGS_FILE" \ + --settings "$SETTINGS_FILE" \ + $MAVEN_PARAMS $MAVEN_OPTIONS + popd +done