Browse Source

OS-8046 add Jenkinsfiles to smartos repos (#911)

Reviewed by: John Levon <john.levon@joyent.com>
Approved by: John Levon <john.levon@joyent.com>
release-20200312
Tim Foster 3 years ago committed by GitHub
parent
commit
853b53863d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 271
      Jenkinsfile
  2. 81
      tools/build_jenkins

271
Jenkinsfile vendored

@ -0,0 +1,271 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Copyright 2020 Joyent, Inc.
*/
@Library('jenkins-joylib@v1.0.4') _
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '30'))
timestamps()
parallelsAlwaysFailFast()
}
// Don't assign a specific agent for the entire job, in order to better
// share resources across jobs. Otherwise, we'd tie up an agent here for
// the duration of all stages for a given build, despite it not doing any
// actual work.
agent none
parameters {
string(
name: 'PLAT_CONFIGURE_ARGS',
defaultValue: '',
description:
'Arguments to smartos-live\'s configure script.\n' +
'By setting any of these, we only run the <b>"default"</b>\n' +
'Jenkins pipeline stage using the user-supplied value.<br/>' +
'<dl>\n' +
'<dt>-c</dt>\n' +
'<dd>clobber Illumos before each build [default: no]</dd>\n' +
'<dt>-d</dt>\n' +
'<dd>build Illumos in DEBUG mode only [default: no]</dd>\n' +
'<dt>-h</dt>\n' +
'<dd>this message</dd>\n' +
'<dt>-p gcc4</dt>\n' +
'<dd>primary compiler version [default: gcc7]</dd>\n' +
'<dt>-P password</dt>\n' +
'<dd>platform root password [default: randomly chosen]</dd>\n' +
'<dt>-S</dt>\n' +
'<dd>do *not* run smatch [default is to run smatch]</dd>\n' +
'<dt>-s gcc7</dt>\n' +
'<dd>shadow compilers, comma delimited (gcc4,gcc#) [default: none]</dd>\n' +
'</dl>'
)
text(
name: 'CONFIGURE_PROJECTS',
defaultValue:
'illumos-extra: master: origin\n' +
'illumos: master: origin\n' +
'local/kbmd: master: origin\n' +
'local/kvm-cmd: master: origin\n' +
'local/kvm: master: origin\n' +
'local/mdata-client: master: origin\n' +
'local/ur-agent: master: origin',
description:
'This parameter is used by smartos-live to decide ' +
'which branches to checkout and configure.</br>\n' +
'The string is formatted:<br/>' +
'<pre>\n' +
'&lt;relative path to ./projects&gt;:&lt;branch name&gt;:[optional git URL]\n' +
'</pre>' +
'In place of a full git url, the keyword \'origin\' ' +
'is allowed in order to specify the default github remote URL.'
)
// The default choice() is the first list item
choice(
name: 'PLATFORM_BUILD_FLAVOR',
choices: ['triton', 'smartos', 'triton-and-smartos'],
description:
'<p><dl>\n' +
'<dt>triton</dt>' +
'<dd>the default, build a platform image and publish it</dd>\n' +
'<dt>smartos</dt>' +
'<dd>build a platform image and smartos artifacts, but do ' +
'not publish a Triton platform image</dd>\n' +
'<dt>triton-and-smartos</dt>' +
'<dd>build both of the above</dd>\n' +
'</dl>' +
'The following are the SmartOS artifacts that will be ' +
'published when selecting one of the smartos options: ' +
'<ul>\n' +
' <li>SmartOS iso image</li>\n' +
' <li>SmartOS usb image</li>\n' +
' <li>SmartOS vmware image</li>\n' +
' <li>SmartOS Changelog file</li>\n' +
'</ul></p>'
)
booleanParam(
name: 'BUILD_STRAP_CACHE',
defaultValue: false,
description: 'This parameter declares whether to build and ' +
'upload a new strap-cache as part of this build. This ' +
'should only be true when triggered by a push to illumos-extra.'
)
}
stages {
stage('check') {
agent {
node {
label 'platform:true && image_ver:18.4.0 && pkgsrc_arch:x86_64 && ' +
'dram:8gb && !virt:kvm && fs:pcfs && fs:ufs && jenkins_agent:2'
customWorkspace "workspace/smartos-${BRANCH_NAME}-check"
}
}
steps{
sh('''
set -o errexit
set -o pipefail
./tools/build_jenkins -c -F check
''')
// We don't mattermost-notify here, as that doesn't add much
// value. The checks should always pass, and it's unlikely
// that developers will care when they do. If they don't
// pass, then the (likely) GitHub PR will be updated with a
// failure status, and the developer can then investigate.
}
}
stage('default') {
agent {
// There seems to be a Jenkins bug where ${WORKSPACE} isn't
// resolved at the time of node declaration, so we can't reuse
// that when setting our custom workspace for each separate
// pipeline stage (to allow users the chance of inspecting
// workspaces from different pipeline stages after the build
// completes).
// Use ${BRANCH_NAME} instead.
node {
label 'platform:true && image_ver:18.4.0 && pkgsrc_arch:x86_64 && ' +
'dram:8gb && !virt:kvm && fs:pcfs && fs:ufs && jenkins_agent:2'
customWorkspace "workspace/smartos-${BRANCH_NAME}-default"
}
}
when {
// We only want to trigger most pipeline stages on either a
// push to master, or an explicit build request from a user.
// Otherwise, every push to a PR branch would cause a build,
// which might be excessive. The exception is the 'check' stage
// above, which is ~ a 2 minute build.
anyOf {
branch 'master'
triggeredBy cause: 'UserIdCause'
}
}
steps {
sh('git clean -fdx')
sh('''
set -o errexit
set -o pipefail
export ENGBLD_BITS_UPLOAD_IMGAPI=true
./tools/build_jenkins -c -S default
''')
archiveArtifacts artifacts: 'output/default/**',
onlyIfSuccessful: false,
allowEmptyArchive: true
joyMattermostNotification(channel: 'jenkins')
joyMattermostNotification(channel: 'os')
}
}
stage('debug') {
agent {
node {
label 'platform:true && image_ver:18.4.0 && pkgsrc_arch:x86_64 && ' +
'dram:8gb && !virt:kvm && fs:pcfs && fs:ufs && jenkins_agent:2'
customWorkspace "workspace/smartos-${BRANCH_NAME}-debug"
}
}
when {
allOf {
anyOf {
branch 'master'
triggeredBy cause: 'UserIdCause'
}
// If a user has set PLAT_CONFIGURE_ARGS, that
// suggests we may have been asked for a special debug, or
// gcc, etc. build. In that case, don't bother building
// any stages which may duplicate the arguments they
// specified. The same goes for the rest of the pipeline
// stages.
environment name: 'PLAT_CONFIGURE_ARGS', value: ''
}
}
steps {
sh('git clean -fdx')
sh('''
set -o errexit
set -o pipefail
export PLAT_CONFIGURE_ARGS="-d $PLAT_CONFIGURE_ARGS"
./tools/build_jenkins -c -d -S debug
''')
archiveArtifacts artifacts: 'output/debug/**',
onlyIfSuccessful: false,
allowEmptyArchive: true
joyMattermostNotification(channel: 'jenkins')
joyMattermostNotification(channel: 'os')
}
}
stage('gcc4') {
agent {
node {
label 'platform:true && image_ver:18.4.0 && pkgsrc_arch:x86_64 && ' +
'dram:8gb && !virt:kvm && fs:pcfs && fs:ufs && jenkins_agent:2'
customWorkspace "workspace/smartos-${BRANCH_NAME}-gcc4"
}
}
when {
allOf {
anyOf {
branch 'master'
triggeredBy cause: 'UserIdCause'
}
environment name: 'PLAT_CONFIGURE_ARGS', value: ''
}
}
steps {
sh('git clean -fdx')
sh('''
export PLAT_CONFIGURE_ARGS="-p gcc4 -r $PLAT_CONFIGURE_ARGS"
# enough to make sure we don't pollute the main Manta dir
export PLATFORM_DEBUG_SUFFIX=-gcc4
./tools/build_jenkins -c -d -S gcc4
''')
archiveArtifacts artifacts: 'output/gcc4/**',
onlyIfSuccessful: false,
allowEmptyArchive: true
}
}
stage('strap-cache') {
agent {
node {
label 'platform:true && image_ver:18.4.0 && pkgsrc_arch:x86_64 && ' +
'dram:8gb && !virt:kvm && fs:pcfs && fs:ufs && jenkins_agent:2'
customWorkspace "workspace/smartos-${BRANCH_NAME}-strap-cache"
}
}
when {
// We only build strap-cache as a result of a push to
// illumos-extra. See the Jenkinsfile in that repository
// which has a build(..) step for smartos-live that sets
// this environment value.
environment name: 'BUILD_STRAP', value: 'true'
}
steps {
sh('git clean -fdx')
sh('''
set -o errexit
set -o pipefail
export MANTA_TOOLS_PATH=/root/bin/
./tools/build_jenkins -c -F strap-cache -S strap-cache
''')
archiveArtifacts artifacts: 'output/strap-cache/**',
onlyIfSuccessful: false,
allowEmptyArchive: true
joyMattermostNotification(channel: 'jenkins')
joyMattermostNotification(channel: 'os')
}
}
}
post {
always {
joyMattermostNotification(channel: 'jenkins')
joyMattermostNotification(channel: 'os')
}
}
}

81
tools/build_jenkins

@ -47,6 +47,7 @@ fi
function usage {
echo "Usage: build_jenkins [options]"
echo "OPTIONS"
echo " -c remove projects dirs prior to building"
echo " -d build a debug platform"
echo " -F <flavor> build one of the following build flavors:"
echo " triton (default) a normal platform build"
@ -54,6 +55,8 @@ function usage {
echo " triton-and-smartos both of the above"
echo " strap-cache build the strap cache tarball"
echo " ctftools build the ctftools tarball"
echo " check do a 'make check' only"
echo " -S <stage> the Jenkins stage name, used to distinguish artifacts"
echo ""
echo "ENVIRONMENT"
echo " BRANCH the branch of smartos-live being built"
@ -83,11 +86,45 @@ function log {
$@ 2>&1 | tee -a ${ENGBLD_LOG}
}
#
# Write the Jenkins build artifacts (log files, etc.) to an output
# directory named after the current Jenkins stage name in order to
# disambiguate the artifacts by stage name. gitstatus.json and the
# generated changelog shouldn't change across stages, but let's err
# on the side of caution.
#
function archive_artifacts {
# Do our best to save all artifacts
set +o errexit
if [[ -n "$JENKINS_STAGE_NAME" ]]; then
echo "Writing Jenkins artifacts to output/$JENKINS_STAGE_NAME"
mkdir -p output/$JENKINS_STAGE_NAME
# move these logs because they're large
mv projects/illumos/log/log.* output/$JENKINS_STAGE_NAME
cp log/* output/$JENKINS_STAGE_NAME
for file in output/bits/artifacts.txt \
output/gitstatus.json \
output/changelog.txt; do
cp $file output/$JENKINS_STAGE_NAME
done
fi
set -o errexit
}
#
# Install a trap handler to archive_artifacts so that it gets called regardless
# of errexit or pipefail.
#
trap archive_artifacts EXIT
#
# Main
#
while getopts "dhF:" opt; do
while getopts "cdhF:S:" opt; do
case "${opt}" in
c)
CLEAN_PROJECTS_DIR=true
;;
d)
# build debug platform bits
ENGBLD_CONFIGURE_DEBUG_ARG='-d'
@ -96,6 +133,9 @@ while getopts "dhF:" opt; do
F)
PLATFORM_BUILD_FLAVOR="${OPTARG}"
;;
S)
JENKINS_STAGE_NAME="${OPTARG}"
;;
h)
usage
;;
@ -111,7 +151,7 @@ if [[ -z "$PLATFORM_BUILD_FLAVOR" ]]; then
fi
case "${PLATFORM_BUILD_FLAVOR}" in
'triton'|'smartos'|'triton-and-smartos'|'strap-cache'|'ctftools')
'triton'|'smartos'|'triton-and-smartos'|'strap-cache'|'ctftools'|'check')
;;
*)
echo "Error: unknown platform build flavor: ${PLATFORM_BUILD_FLAVOR}"
@ -135,6 +175,18 @@ done
mkdir -p ${ENGBLD_LOGDIR}
touch ${ENGBLD_LOG}
#
# The Jenkins GitHub Pull Request Builder plugin overrides the git
# 'remote.origin.fetch' config setting, along the lines of
# "git config --add remote.origin.fetch +refs/heads/prr-OS-8046:refs/remotes/origin/prr-OS-8046"
# which will break the 'tools/build_changelog' script as we won't have an
# accurate list of the 'release-*' branches when building PRs.
# Reset that now to something sane, and force a fetch.
# This will not modify which branch is currently checked out.
#
git config --replace-all remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git remote update
# Remove any old logs so that these don't get swept up as Jenkins artifacts
log rm -rf log projects/illumos/log
@ -148,10 +200,15 @@ fi
#
# ${CONFIGURE_PROJECTS} is multi-line jenkins parameter, set so that users can
# specify which branches of the repositories in the smartos-live 'projects'
# framework to build, and from where they should be cloned.
# framework to build, and from where they should be cloned. For release builds,
# override all repositories.
#
if [[ -z "${CONFIGURE_PROJECTS}" ]]; then
echo "using default configure-projects"
echo "Using default configure-projects"
elif [[ -n "${ENGBLD_RELEASE}" ]]; then
echo "Doing release build - setting configure projects to:"
sed -e "s/ master: / ${BRANCH}: /g" default.configure-projects > configure-projects
cat configure-projects
else
echo "${CONFIGURE_PROJECTS}" > configure-projects
fi
@ -159,6 +216,13 @@ fi
# this can be set to " " to avoid a full strap rebuild for dev purposes
FORCE_STRAP_REBUILD_ARG=${FORCE_STRAP_REBUILD_ARG:--r}
if [[ -n "${CLEAN_PROJECTS_DIR}" ]]; then
echo "Removing potentially stale projects dirs"
for proj in $(cat configure-projects | awk -F: '{print $1}'); do
log_cmd rm -rf projects/$proj
done
fi
# Configure the build based on the arguments we've gathered
log_cmd ./configure ${FORCE_STRAP_REBUILD_ARG} \
${ENGBLD_CONFIGURE_DEBUG_ARG} \
@ -166,15 +230,15 @@ log_cmd ./configure ${FORCE_STRAP_REBUILD_ARG} \
case "${PLATFORM_BUILD_FLAVOR}" in
'triton')
log_cmd gmake common-release
log_cmd gmake common-release
log_cmd gmake triton-release
;;
'smartos')
log_cmd gmake common-release
log_cmd gmake common-release
log_cmd gmake smartos-only-release
;;
'triton-and-smartos')
log_cmd gmake common-release
log_cmd gmake common-release
log_cmd gmake triton-smartos-release
;;
'strap-cache')
@ -183,6 +247,9 @@ case "${PLATFORM_BUILD_FLAVOR}" in
'ctftools')
log_cmd gmake ctftools-release
;;
'check')
log_cmd gmake check
;;
esac
#

Loading…
Cancel
Save