summaryrefslogtreecommitdiff
path: root/vars
diff options
context:
space:
mode:
Diffstat (limited to 'vars')
-rw-r--r--vars/README.md6
-rw-r--r--vars/getGitBranchName.groovy21
-rw-r--r--vars/getGitRepoName.groovy20
-rw-r--r--vars/getGitRepoURL.groovy20
-rw-r--r--vars/isCustomBuild.groovy26
-rw-r--r--vars/setDescription.groovy38
6 files changed, 131 insertions, 0 deletions
diff --git a/vars/README.md b/vars/README.md
new file mode 100644
index 00000000..ca2f821f
--- /dev/null
+++ b/vars/README.md
@@ -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.
diff --git a/vars/getGitBranchName.groovy b/vars/getGitBranchName.groovy
new file mode 100644
index 00000000..133734da
--- /dev/null
+++ b/vars/getGitBranchName.groovy
@@ -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]
+}
+
diff --git a/vars/getGitRepoName.groovy b/vars/getGitRepoName.groovy
new file mode 100644
index 00000000..058e4ff5
--- /dev/null
+++ b/vars/getGitRepoName.groovy
@@ -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()
+}
+
diff --git a/vars/getGitRepoURL.groovy b/vars/getGitRepoURL.groovy
new file mode 100644
index 00000000..d36b48e6
--- /dev/null
+++ b/vars/getGitRepoURL.groovy
@@ -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
+}
+
diff --git a/vars/isCustomBuild.groovy b/vars/isCustomBuild.groovy
new file mode 100644
index 00000000..301fdd42
--- /dev/null
+++ b/vars/isCustomBuild.groovy
@@ -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
+}
diff --git a/vars/setDescription.groovy b/vars/setDescription.groovy
new file mode 100644
index 00000000..a503bc28
--- /dev/null
+++ b/vars/setDescription.groovy
@@ -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()
+}
+