diff options
| author | dd <dd@wx.tnyzeq.icu> | 2024-05-26 13:52:21 +0200 |
|---|---|---|
| committer | dd <dd@wx.tnyzeq.icu> | 2024-05-26 13:52:21 +0200 |
| commit | ea2dab8895a85cad6933ccfa0bfc9e24160613dd (patch) | |
| tree | 4939a00bb32bb45c066e8594859440821e26381d | |
| parent | 8f66db46759f85473d9bda4dee8bbc89aa918b18 (diff) | |
| download | vyos-jenkins-ea2dab8895a85cad6933ccfa0bfc9e24160613dd.tar.gz vyos-jenkins-ea2dab8895a85cad6933ccfa0bfc9e24160613dd.zip | |
added script for seeding jobs
| -rw-r--r-- | jenkins-scripts/jobTemplate.xml | 64 | ||||
| -rw-r--r-- | jenkins-scripts/jobs.json | 443 | ||||
| -rwxr-xr-x | jenkins-scripts/seed-jobs.sh | 108 | ||||
| -rwxr-xr-x | jenkins-scripts/setup-periodic-trigger-for-all-jobs.sh | 38 | ||||
| -rw-r--r-- | readme.md | 54 |
5 files changed, 684 insertions, 23 deletions
diff --git a/jenkins-scripts/jobTemplate.xml b/jenkins-scripts/jobTemplate.xml new file mode 100644 index 0000000..2a41c69 --- /dev/null +++ b/jenkins-scripts/jobTemplate.xml @@ -0,0 +1,64 @@ +<?xml version="1.1" encoding="UTF-8"?> +<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch@783.va_6eb_ef636fb_d"> + <actions/> + <description>~DESCRIPTION~</description> + <properties> + <org.jenkinsci.plugins.docker.workflow.declarative.FolderConfig plugin="docker-workflow@572.v950f58993843"> + <dockerLabel/> + <registry plugin="docker-commons@439.va_3cb_0a_6a_fb_29"/> + </org.jenkinsci.plugins.docker.workflow.declarative.FolderConfig> + </properties> + <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api@2.1169.va_f810c56e895"> + <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/> + </folderViews> + <healthMetrics/> + <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api@2.1169.va_f810c56e895"> + <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/> + </icon> + <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder@6.928.v7c780211d66e"> + <pruneDeadBranches>true</pruneDeadBranches> + <daysToKeep>-1</daysToKeep> + <numToKeep>-1</numToKeep> + <abortBuilds>false</abortBuilds> + </orphanedItemStrategy> + <triggers> + <com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger plugin="cloudbees-folder@6.928.v7c780211d66e"> + <spec>H/15 * * * *</spec> + <interval>3600000</interval> + </com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger> + </triggers> + <disabled>false</disabled> + <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api@2.1169.va_f810c56e895"> + <data> + <jenkins.branch.BranchSource> + <source class="jenkins.plugins.git.GitSCMSource" plugin="git@5.2.2"> + <id>61655632-2acc-4cf1-be05-2bd1530809a4</id> + <remote>~GIT_URL~</remote> + <credentialsId/> + <traits> + <jenkins.plugins.git.traits.BranchDiscoveryTrait/> + <jenkins.scm.impl.trait.RegexSCMHeadFilterTrait plugin="scm-api@690.vfc8b_54395023"> + <regex>~BRANCH_REGEX~</regex> + </jenkins.scm.impl.trait.RegexSCMHeadFilterTrait> + <jenkins.plugins.git.traits.CloneOptionTrait> + <extension class="hudson.plugins.git.extensions.impl.CloneOption"> + <shallow>false</shallow> + <noTags>false</noTags> + <reference/> + <honorRefspec>false</honorRefspec> + </extension> + </jenkins.plugins.git.traits.CloneOptionTrait> + </traits> + </source> + <strategy class="jenkins.branch.DefaultBranchPropertyStrategy"> + <properties class="empty-list"/> + </strategy> + </jenkins.branch.BranchSource> + </data> + <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/> + </sources> + <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory"> + <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/> + <scriptPath>~JENKINSFILE_PATH~</scriptPath> + </factory> +</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject> diff --git a/jenkins-scripts/jobs.json b/jenkins-scripts/jobs.json new file mode 100644 index 0000000..793543a --- /dev/null +++ b/jenkins-scripts/jobs.json @@ -0,0 +1,443 @@ +[ + { + "name": "aws-gateway-load-balancer-tunnel-handler", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/aws-gateway-load-balancer-tunnel-handler/Jenkinsfile" + }, + { + "name": "ddclient", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/ddclient/Jenkinsfile" + }, + { + "name": "dropbear", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/dropbear/Jenkinsfile" + }, + { + "name": "ethtool", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/ethtool/Jenkinsfile" + }, + { + "name": "frr", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/frr/Jenkinsfile" + }, + { + "name": "hostap", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/hostap/Jenkinsfile" + }, + { + "name": "hsflowd", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/hsflowd/Jenkinsfile" + }, + { + "name": "hvinfo", + "description": "shared", + "gitUrl": "https://github.com/vyos/hvinfo.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "ipaddrcheck", + "description": "shared", + "gitUrl": "https://github.com/vyos/ipaddrcheck.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "iproute2", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/iproute2/Jenkinsfile" + }, + { + "name": "isc-dhcp", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/isc-dhcp/Jenkinsfile" + }, + { + "name": "keepalived", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/keepalived/Jenkinsfile" + }, + { + "name": "libnss-mapuser", + "description": "shared", + "gitUrl": "https://github.com/vyos/libnss-mapuser.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "libnss-tacplus", + "description": "shared", + "gitUrl": "https://github.com/dd010101/vyos-missing.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/libnss-tacplus/Jenkinsfile" + }, + { + "name": "libpam-radius-auth", + "description": "shared", + "gitUrl": "https://github.com/vyos/libpam-radius-auth.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "libvyosconfig", + "description": "shared", + "gitUrl": "https://github.com/vyos/libvyosconfig.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "linux-kernel", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/linux-kernel/Jenkinsfile" + }, + { + "name": "live-boot", + "description": "shared", + "gitUrl": "https://github.com/vyos/live-boot.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "mdns-repeater", + "description": "shared", + "gitUrl": "https://github.com/vyos/mdns-repeater.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "minisign", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/minisign/Jenkinsfile" + }, + { + "name": "ndppd", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/ndppd/Jenkinsfile" + }, + { + "name": "netfilter", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/netfilter/Jenkinsfile" + }, + { + "name": "ocserv", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/ocserv/Jenkinsfile" + }, + { + "name": "opennhrp", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/opennhrp/Jenkinsfile" + }, + { + "name": "openvpn-otp", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/openvpn-otp/Jenkinsfile" + }, + { + "name": "owamp", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/owamp/Jenkinsfile" + }, + { + "name": "pam_tacplus", + "description": "sagitta-only", + "gitUrl": "https://github.com/dd010101/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/pam_tacplus/Jenkinsfile" + }, + { + "name": "pmacct", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/pmacct/Jenkinsfile" + }, + { + "name": "pyhumps", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/pyhumps/Jenkinsfile" + }, + { + "name": "python3-inotify", + "description": "equuleus-only", + "gitUrl": "https://github.com/dd010101/vyos-missing.git", + "branchRegex": "(equuleus)", + "jenkinsfilePath": "packages/python3-inotify/Jenkinsfile" + }, + { + "name": "radvd", + "description": "sagitta-only", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/radvd/Jenkinsfile" + }, + { + "name": "strongswan", + "description": "sagitta-only", + "gitUrl": "https://github.com/dd010101/vyos-build.git", + "branchRegex": "sagitta", + "jenkinsfilePath": "packages/strongswan/Jenkinsfile" + }, + { + "name": "telegraf", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-build.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/telegraf/Jenkinsfile" + }, + { + "name": "udp-broadcast-relay", + "description": "shared", + "gitUrl": "https://github.com/vyos/udp-broadcast-relay.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vpp", + "description": "shared", + "gitUrl": "https://github.com/dd010101/vyos-missing.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "packages/vpp/Jenkinsfile" + }, + { + "name": "vyatta-bash", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-bash.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-biosdevname", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-biosdevname.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cfg-firewall", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cfg-firewall.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cfg-qos", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cfg-qos.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cfg-quagga", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cfg-quagga.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cfg-system", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cfg-system.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cfg-vpn", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cfg-vpn.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cfg", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cfg.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-cluster", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-cluster.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-config-mgmt", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-config-mgmt.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-conntrack", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-conntrack.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-nat", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-nat.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-op-firewall", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-op-firewall.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-op-qos", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-op-qos.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-op-vpn", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-op-vpn.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-op", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-op.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-wanloadbalance", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-wanloadbalance.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyatta-zone", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyatta-zone.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-1x", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-1x.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-cloud-init", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-cloud-init.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-http-api-tools", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-http-api-tools.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-nhrp", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-nhrp.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-opennhrp", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-opennhrp.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-strongswan", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-strongswan.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-user-utils", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-user-utils.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-utils", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-utils.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-world", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-world.git", + "branchRegex": "(equuleus|sagitta)", + "jenkinsfilePath": "Jenkinsfile" + }, + { + "name": "vyos-xe-guest-utilities", + "description": "shared", + "gitUrl": "https://github.com/vyos/vyos-xe-guest-utilities.git", + "branchRegex": "(equuleus|sagitta|current)", + "jenkinsfilePath": "Jenkinsfile" + } +]
\ No newline at end of file diff --git a/jenkins-scripts/seed-jobs.sh b/jenkins-scripts/seed-jobs.sh new file mode 100755 index 0000000..b9bc19b --- /dev/null +++ b/jenkins-scripts/seed-jobs.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash +set -e + +# +# This script seeds Jenkins jobs via list of packages in jobs.json +# it iterates through all packages +# it checks if job for package exists +# it updates job if exists otherwise creates new one +# finally it starts first build for available branches +# +# This script has two modes, first mode is create +# ./seed-jobs.sh create +# this will update or create jobs +# +# Second mode is build +# ./seed-jobs.sh build +# this will trigger build for all jobs +# +# You need to wait after create some time, Jenkins need to complete branch indexing. +# Check Jenkins Build Queue and Build Executor Status to be empty. Then you can run build. +# +# dependency: apt install -y xmlstarlet jq +# + +jenkinsUser="" # fill your username here or set via export JENKINS_USER +jenkinsToken="" # fill your token here or set via export JENKINS_TOKEN +jenkinsHost="172.17.17.17:8080" +workDir="/opt/jenkins-cli" + +mkdir -p "$workDir" + +templatePath="jobTemplate.xml" +jenkinsUser=${jenkinsUser:-$JENKINS_USER} +jenkinsToken=${jenkinsToken:-$JENKINS_TOKEN} +jenkinsUrl="http://${jenkinsUser}:${jenkinsToken}@$jenkinsHost" + +mode="$1" +availableModes=("create" "build") + +get() { + curl -sS -g "${jenkinsUrl}${1}" +} + +post() { + curl -sS -g -X POST "${jenkinsUrl}${1}" +} + +push() { + curl -sS -g -X POST -d "@${2}" -H "Content-Type: text/xml" "${jenkinsUrl}${1}" +} + +if [[ "$mode" == "create" ]]; then + while read item + do + jobName=$(echo "$item" | jq -r .name) + echo -n "$jobName:" + + description=$(echo "$item" | jq -r .description) + gitUrl=$(echo "$item" | jq -r .gitUrl) + branchRegex=$(echo "$item" | jq -r .branchRegex) + jenkinsfilePath=$(echo "$item" | jq -r .jenkinsfilePath) + + # create job.xml by using jobTemplate.xml + jobPath="$workDir/$jobName.xml" + project="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" + branchSource="$project/sources/data/jenkins.branch.BranchSource/source" + regexTrait="$branchSource/traits/jenkins.scm.impl.trait.RegexSCMHeadFilterTrait" + xmlstarlet ed --update "//$project/description" --value "$description" \ + --update "//$branchSource/remote" --value "$gitUrl" \ + --update "//$regexTrait/regex" --value "$branchRegex" \ + --update "//$project/factory/scriptPath" --value "$jenkinsfilePath" \ + "$templatePath" > "$jobPath" 2>/dev/null + + # check if job exists + result=$(get "/checkJobName?value=$jobName") + if [[ "$result" == *"already exists"* ]]; then + # update job + push "/job/$jobName/config.xml" "$jobPath" + else + # create job + push "/createItem?name=$jobName" "$jobPath" + fi + + echo " ok" + + done < <(cat jobs.json | jq -c '.[]') + +elif [[ "$mode" == "build" ]]; then + + get "/api/xml?tree=jobs[name]" | xmlstarlet sel -t -v "//hudson/job/name" | while read jobName; do + + echo -n "$jobName:" + + # trigger build - it's not easy to know what branches job has + # thus we trigger all possible ones and ignore not found + post "/job/$jobName/job/equuleus/build" > /dev/null 2>/dev/null + post "/job/$jobName/job/sagitta/build" > /dev/null 2>/dev/null + post "/job/$jobName/job/current/build" > /dev/null 2>/dev/null + + echo " ok" + + done + +else + echo "ERROR: unknown mode '$mode'" + echo "available modes: ${availableModes[*]}" +fi + diff --git a/jenkins-scripts/setup-periodic-trigger-for-all-jobs.sh b/jenkins-scripts/setup-periodic-trigger-for-all-jobs.sh index 4835ce2..2a07827 100755 --- a/jenkins-scripts/setup-periodic-trigger-for-all-jobs.sh +++ b/jenkins-scripts/setup-periodic-trigger-for-all-jobs.sh @@ -15,38 +15,38 @@ set -e user="YOUR_JENKINS_USERNAME" token="YOUR_JENKINS_TOKEN" jenkinsUrl="http://${user}:${token}@172.17.17.17:8080" -workingDir="/opt/jenkins-cli" +workDir="/opt/jenkins-cli" -mkdir -p "$workingDir" +mkdir -p "$workDir" get() { - curl -sS -g "${jenkinsUrl}${1}" + curl -sS -g "${jenkinsUrl}${1}" } push() { - curl -sS -g -X POST -d "@${2}" -H "Content-Type: text/xml" "${jenkinsUrl}${1}" + curl -sS -g -X POST -d "@${2}" -H "Content-Type: text/xml" "${jenkinsUrl}${1}" } get "/api/xml?tree=jobs[name]" | xmlstarlet sel -t -v "//hudson/job/name" | while read jobName; do - echo -n "$jobName:" + echo -n "$jobName:" - originalPath="$workingDir/$jobName.xml" - get "/job/$jobName/config.xml" > "$originalPath" + originalPath="$workDir/$jobName.xml" + get "/job/$jobName/config.xml" > "$originalPath" - updatedPath="$workingDir/${jobName}_updated.xml" - project="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" - trigger="com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger" - plugin="cloudbees-folder@6.928.v7c780211d66e" - xmlstarlet ed --delete "//$project/triggers/$trigger" \ - --subnode "//$project/triggers" --type elem --name "$trigger" \ - --append "//$project/triggers/$trigger" --type attr --name plugin --value "$plugin" \ - --subnode "//$project/triggers/$trigger" --type elem --name spec --value "H/15 * * * *" \ - --subnode "//$project/triggers/$trigger" --type elem --name interval --value "3600000" \ - "$originalPath" > "$updatedPath" 2>/dev/null + updatedPath="$workDir/${jobName}_updated.xml" + project="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" + trigger="com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger" + plugin="cloudbees-folder@6.928.v7c780211d66e" + xmlstarlet ed --delete "//$project/triggers/$trigger" \ + --subnode "//$project/triggers" --type elem --name "$trigger" \ + --append "//$project/triggers/$trigger" --type attr --name plugin --value "$plugin" \ + --subnode "//$project/triggers/$trigger" --type elem --name spec --value "H/15 * * * *" \ + --subnode "//$project/triggers/$trigger" --type elem --name interval --value "3600000" \ + "$originalPath" > "$updatedPath" 2>/dev/null - push "/job/$jobName/config.xml" "$updatedPath" + push "/job/$jobName/config.xml" "$updatedPath" - echo " ok" + echo " ok" done @@ -458,8 +458,57 @@ EOF chmod +x /usr/local/bin/uncron-add ``` -Multibranch Pipelines +Multibranch Pipelines (by script) -- + +Experimental script exists to automate pipeline/job creation. + +Check the `jenkins-scripts/seed-jobs.sh` for details. + +**Get the script seed-jobs.sh** + +And it's assets (jobs.json, jobTemplate.xml). + +``` +git clone git@github.com:dd010101/vyos-jenkins.git +cd vyos-jenkins/jenkins-scripts +``` + +**Install dependencies** + +``` +apt install -y xmlstarlet jq +``` + +**Adjust settings to suit your Jenkins** + +``` +cat seed-jobs.sh +``` + +**Create jobs** + +Then wait for branch indexing to complete. + +``` +./seed-jobs.sh create +``` + +**After branch indexing you can trigger build for everything** + +Make sure you have >=16GB RAM or 8GB RAM + 8GB swap, since running build for everything like this eats more memory +than building one by one this is also dependent on how many Number of executors you have. + +``` +./seed-jobs.sh build +``` + +Now wait for build to complete and check Build History and Dashboard for failed builds. If you find any failed +builds then read Console Output to see why it did failed. + +Multibranch Pipelines (manual) +-- + Use + button on Jenkins dashboard to add Multibranch Pipeline. Each Jenkinsfile needs its own Multibranch Pipeline, the setup is the same for all packages, and you just adjust location of Jenkinsfile and/or GIT repository to whatever you want to build. See packages info bellow for list of all GIT repository and location their Jenkinsfile. @@ -527,9 +576,6 @@ Interval: 1 hour Jenkins will check the source GIT repository if changes were made and execute automatic build if needed. This will keep packages up to date. -TODO: find a way how to populate Multibranch Pipeline automatically from list in order to avoid the need to -create all pipelines by hand since it's the most tedious part due to a lot of repetition. - Try to build -- |
