diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-06-20 23:41:46 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-06-20 23:52:25 +0200 |
commit | 76e05e019e0e81b7d28516d6f4299421590f6427 (patch) | |
tree | 275917ccef12298f671b84cfa69e2b863ca935b3 | |
parent | ee8c079cfae7472cf2963c43836e3bb63a0b52d8 (diff) | |
download | vyos-build-76e05e019e0e81b7d28516d6f4299421590f6427.tar.gz vyos-build-76e05e019e0e81b7d28516d6f4299421590f6427.zip |
Jenkins: lib: buildPackage() parameters are all optional now
- description: Arbitrary text to print on Jenkins Job Description
instead of package name
- pkgList: Multiple packages can be build at once in a single Pipeline run
- buildCmd: replace default build command "dpkg-buildpackage -uc -us -tc -b"
with this custom version
-rw-r--r-- | vars/buildPackage.groovy | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/vars/buildPackage.groovy b/vars/buildPackage.groovy index 927ced38..262db472 100644 --- a/vars/buildPackage.groovy +++ b/vars/buildPackage.groovy @@ -15,8 +15,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -def call(description, pkgList) { - /* Only keep the 10 most recent builds. */ +def call(description=null, pkgList=null, buildCmd=null) { + // - description: Arbitrary text to print on Jenkins Job Description + // instead of package name + // - pkgList: Multiple packages can be build at once in a single Pipeline run + // - buildCmd: replace default build command "dpkg-buildpackage -uc -us -tc -b" + // with this custom version + + // Only keep the 10 most recent builds def projectProperties = [ [$class: 'BuildDiscarderProperty',strategy: [$class: 'LogRotator', numToKeepStr: '10']], ] @@ -76,16 +82,23 @@ def call(description, pkgList) { script { checkout scm + // Display Git commit Id used on Jenkinsfile on the + // Jenkins Job "Build History" pane def commitId = sh(returnStdout: true, script: 'git rev-parse --short=11 HEAD').trim() currentBuild.description = sprintf('Git SHA1: %s', commitId[-11..-1]) - pkgList.each { pkg -> - dir(env.BASE_DIR + pkg.name) { - checkout([$class: 'GitSCM', - doGenerateSubmoduleConfigurations: false, - extensions: [[$class: 'CleanCheckout']], - branches: [[name: pkg.scmCommit]], - userRemoteConfigs: [[url: pkg.scmUrl]]]) + if (pkgList) { + // Fetch individual package source code, but only if a URL is defined, this will + // let us reuse this script for packages like vyos-1x which ship a Jenkinfile in + // their repositories root folder. + pkgList.each { pkg -> + dir(env.BASE_DIR + pkg.name) { + checkout([$class: 'GitSCM', + doGenerateSubmoduleConfigurations: false, + extensions: [[$class: 'CleanCheckout']], + branches: [[name: pkg.scmCommit]], + userRemoteConfigs: [[url: pkg.scmUrl]]]) + } } } sh "pwd; ls -al" @@ -104,11 +117,17 @@ def call(description, pkgList) { } steps { script { - pkgList.each { pkg -> - dir(env.BASE_DIR + pkg.name) { - sh "pwd; ls -al" - sh pkg.buildCmd + if (pkgList) { + pkgList.each { pkg -> + dir(env.BASE_DIR + pkg.name) { + sh "pwd; ls -al" + sh pkg.buildCmd + } } + } else if (buildCmd) { + sh buildCmd + } else { + sh "dpkg-buildpackage -uc -us -tc -b" } } } |