mirror of
https://github.com/vyos/vyos-build.git
synced 2025-10-01 20:28:40 +02:00
Jenkins: initial support for shared build libraries
Instead of writing the same code over and over again, place the common parts into a Jenkins Library which is then consumed by every individual build Job. This not only makes it less complex, but also increases maintainability by several magnitudes.
This commit is contained in:
parent
3656075d27
commit
7ab2724c33
93
packages/netfilter/Jenkinsfile
vendored
93
packages/netfilter/Jenkinsfile
vendored
@ -14,52 +14,8 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
@NonCPS
|
@NonCPS
|
||||||
|
/* Using a version specifier library, use 'current' branch */
|
||||||
def getGitBranchName() {
|
@Library('vyos-build@current')
|
||||||
def branch = scm.branches[0].name
|
|
||||||
return branch.split('/')[-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
def getGitRepoURL() {
|
|
||||||
return scm.userRemoteConfigs[0].url
|
|
||||||
}
|
|
||||||
|
|
||||||
def getGitRepoName() {
|
|
||||||
return getGitRepoURL().split('/').last()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if this is a custom build launched on any project fork.
|
|
||||||
// Returns false if this is build from git@github.com:vyos/<reponame>.
|
|
||||||
// <reponame> can be e.g. vyos-1x.git or vyatta-op.git
|
|
||||||
def isCustomBuild() {
|
|
||||||
// GitHub organisation base URL
|
|
||||||
def gitURI = 'git@github.com:vyos/' + getGitRepoName()
|
|
||||||
def httpURI = 'https://github.com/vyos/' + getGitRepoName()
|
|
||||||
|
|
||||||
return !((getGitRepoURL() == gitURI) || (getGitRepoURL() == httpURI)) || env.CHANGE_ID
|
|
||||||
}
|
|
||||||
|
|
||||||
def setDescription() {
|
|
||||||
def item = Jenkins.instance.getItemByFullName(env.JOB_NAME)
|
|
||||||
|
|
||||||
// build up the main description text
|
|
||||||
def description = ""
|
|
||||||
description += "<h2>VyOS individual package build: " + getGitRepoName().replace('.git', '') + "</h2>"
|
|
||||||
|
|
||||||
if (isCustomBuild()) {
|
|
||||||
description += "<p style='border: 3px dashed red; width: 50%;'>"
|
|
||||||
description += "<b>Build not started from official Git repository!</b><br>"
|
|
||||||
description += "<br>"
|
|
||||||
description += "Repository: <font face = 'courier'>" + getGitRepoURL() + "</font><br>"
|
|
||||||
description += "Branch: <font face = 'courier'>" + getGitBranchName() + "</font><br>"
|
|
||||||
description += "</p>"
|
|
||||||
} else {
|
|
||||||
description += "Sources taken from Git branch: <font face = 'courier'>" + getGitBranchName() + "</font><br>"
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setDescription(description)
|
|
||||||
item.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Only keep the 10 most recent builds. */
|
/* Only keep the 10 most recent builds. */
|
||||||
def projectProperties = [
|
def projectProperties = [
|
||||||
@ -71,20 +27,20 @@ setDescription()
|
|||||||
|
|
||||||
node('Docker') {
|
node('Docker') {
|
||||||
stage('Define Agent') {
|
stage('Define Agent') {
|
||||||
script {
|
script {
|
||||||
// create container name on demand
|
// create container name on demand
|
||||||
def branchName = getGitBranchName()
|
def branchName = getGitBranchName()
|
||||||
// Adjust PR target branch name so we can re-map it to the proper
|
// Adjust PR target branch name so we can re-map it to the proper
|
||||||
// Docker image. CHANGE_ID is set only for pull requests, so it is
|
// Docker image. CHANGE_ID is set only for pull requests, so it is
|
||||||
// safe to access the pullRequest global variable
|
// safe to access the pullRequest global variable
|
||||||
if (env.CHANGE_ID) {
|
if (env.CHANGE_ID) {
|
||||||
branchName = "${env.CHANGE_TARGET}".toLowerCase()
|
branchName = "${env.CHANGE_TARGET}".toLowerCase()
|
||||||
}
|
}
|
||||||
if (branchName.equals("master")) {
|
if (branchName.equals("master")) {
|
||||||
branchName = "current"
|
branchName = "current"
|
||||||
}
|
}
|
||||||
env.DOCKER_IMAGE = "vyos/vyos-build:" + branchName
|
env.DOCKER_IMAGE = "vyos/vyos-build:" + branchName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,13 +57,20 @@ pipeline {
|
|||||||
CHANGESET_DIR = "**/${env.BASE_DIR}*"
|
CHANGESET_DIR = "**/${env.BASE_DIR}*"
|
||||||
}
|
}
|
||||||
options {
|
options {
|
||||||
|
disableConcurrentBuilds()
|
||||||
timeout(time: 60, unit: 'MINUTES')
|
timeout(time: 60, unit: 'MINUTES')
|
||||||
timestamps()
|
timestamps()
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Fetch') {
|
stage('Fetch') {
|
||||||
when {
|
when {
|
||||||
changeset "${env.CHANGESET_DIR}"
|
beforeOptions true
|
||||||
|
beforeAgent true
|
||||||
|
anyOf {
|
||||||
|
changeset "${env.CHANGESET_DIR}"
|
||||||
|
triggeredBy 'TimerTrigger'
|
||||||
|
triggeredBy cause: "UserIdCause"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
@ -190,9 +153,11 @@ pipeline {
|
|||||||
deleteDir()
|
deleteDir()
|
||||||
}
|
}
|
||||||
success {
|
success {
|
||||||
// archive *.deb artifact on custom builds, deploy to repo otherwise
|
script {
|
||||||
if ( isCustomBuild()) {
|
// archive *.deb artifact on custom builds, deploy to repo otherwise
|
||||||
archiveArtifacts artifacts: '**/*.deb', allowEmptyArchive: true
|
if ( isCustomBuild()) {
|
||||||
|
archiveArtifacts artifacts: '**/*.deb', allowEmptyArchive: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
vars/README.md
Normal file
6
vars/README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Jenkins Build Library
|
||||||
|
|
||||||
|
Instead of writing the same code over and over again, place the common
|
||||||
|
parts into a Jenkins Library which is then consumed by every individual
|
||||||
|
build Job. This not only makes it less complex, it also increases
|
||||||
|
maintainability by several magnitudes.
|
||||||
21
vars/getGitBranchName.groovy
Normal file
21
vars/getGitBranchName.groovy
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env groovy
|
||||||
|
// Copyright (C) 2020 VyOS maintainers and contributors
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// in order to easy exprort images built to "external" world
|
||||||
|
// it under the terms of the GNU General Public License version 2 or later as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// 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() {
|
||||||
|
def branch = scm.branches[0].name
|
||||||
|
return branch.split('/')[-1]
|
||||||
|
}
|
||||||
|
|
||||||
20
vars/getGitRepoName.groovy
Normal file
20
vars/getGitRepoName.groovy
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env groovy
|
||||||
|
// Copyright (C) 2020 VyOS maintainers and contributors
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// in order to easy exprort images built to "external" world
|
||||||
|
// it under the terms of the GNU General Public License version 2 or later as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// 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() {
|
||||||
|
return getGitRepoURL().split('/').last()
|
||||||
|
}
|
||||||
|
|
||||||
20
vars/getGitRepoURL.groovy
Normal file
20
vars/getGitRepoURL.groovy
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env groovy
|
||||||
|
// Copyright (C) 2020 VyOS maintainers and contributors
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// in order to easy exprort images built to "external" world
|
||||||
|
// it under the terms of the GNU General Public License version 2 or later as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// 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() {
|
||||||
|
return scm.userRemoteConfigs[0].url
|
||||||
|
}
|
||||||
|
|
||||||
26
vars/isCustomBuild.groovy
Normal file
26
vars/isCustomBuild.groovy
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env groovy
|
||||||
|
// Copyright (C) 2020 VyOS maintainers and contributors
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// in order to easy exprort images built to "external" world
|
||||||
|
// it under the terms of the GNU General Public License version 2 or later as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// 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() {
|
||||||
|
// Returns true if this is a custom build launched on any project fork.
|
||||||
|
// Returns false if this is build from git@github.com:vyos/<reponame>.
|
||||||
|
// <reponame> can be e.g. vyos-1x.git or vyatta-op.git
|
||||||
|
// GitHub organisation base URL
|
||||||
|
def gitURI = 'git@github.com:vyos/' + getGitRepoName()
|
||||||
|
def httpURI = 'https://github.com/vyos/' + getGitRepoName()
|
||||||
|
|
||||||
|
return !((getGitRepoURL() == gitURI) || (getGitRepoURL() == httpURI)) || env.CHANGE_ID
|
||||||
|
}
|
||||||
38
vars/setDescription.groovy
Normal file
38
vars/setDescription.groovy
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env groovy
|
||||||
|
// Copyright (C) 2020 VyOS maintainers and contributors
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// in order to easy exprort images built to "external" world
|
||||||
|
// it under the terms of the GNU General Public License version 2 or later as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// 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() {
|
||||||
|
def item = Jenkins.instance.getItemByFullName(env.JOB_NAME)
|
||||||
|
|
||||||
|
// build up the main description text
|
||||||
|
def description = ""
|
||||||
|
description += "<h2>VyOS individual package build: " + getGitRepoName().replace('.git', '') + "</h2>"
|
||||||
|
|
||||||
|
if (isCustomBuild()) {
|
||||||
|
description += "<p style='border: 3px dashed red; width: 50%;'>"
|
||||||
|
description += "<b>Build not started from official Git repository!</b><br>"
|
||||||
|
description += "<br>"
|
||||||
|
description += "Repository: <font face = 'courier'>" + getGitRepoURL() + "</font><br>"
|
||||||
|
description += "Branch: <font face = 'courier'>" + getGitBranchName() + "</font><br>"
|
||||||
|
description += "</p>"
|
||||||
|
} else {
|
||||||
|
description += "Sources taken from Git branch: <font face = 'courier'>" + getGitBranchName() + "</font><br>"
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setDescription(description)
|
||||||
|
item.save()
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user