Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Backup all base image jobs from Jenkins #343

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
40 changes: 40 additions & 0 deletions automation/backup_jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e

JENKINS_URL="http://your-jenkins-url"
JENKINS_USER="your-username"
JENKINS_API_TOKEN="your-api-token"
JENKINS_CLI_JAR="$(dirname "$(realpath "$0")")/jenkins-cli.jar"
BACKUP_DIR="$(dirname "$(realpath "$0")")/../jenkins"
JOB_PATTERN="balena-.+-(alpine|debian|fedora|ubuntu)(-.+)?"
MAX_RETRIES=3

# Download the Jenkins CLI jar file if it doesn't exist
if [ ! -f "$JENKINS_CLI_JAR" ]; then
wget -O $JENKINS_CLI_JAR "$JENKINS_URL/jnlpJars/jenkins-cli.jar"
fi

# Get the list of all jobs
all_jobs=$(java -jar $JENKINS_CLI_JAR -s $JENKINS_URL -auth $JENKINS_USER:$JENKINS_API_TOKEN list-jobs)

# Export jobs matching the regex pattern
for job in $all_jobs; do
if [[ $job =~ $JOB_PATTERN ]]; then
echo "Exporting job: $job"
success=false
retries=0
while [ $retries -lt $MAX_RETRIES ] && [ $success == false ]; do
if java -jar $JENKINS_CLI_JAR -s $JENKINS_URL -auth $JENKINS_USER:$JENKINS_API_TOKEN get-job $job > "$BACKUP_DIR/$job.xml"; then
success=true
else
retries=$((retries + 1))
echo "Failed to export job $job. Retrying... ($retries/$MAX_RETRIES)"
sleep 5
fi
done
if [ $success == false ]; then
echo "Failed to export job $job after $MAX_RETRIES attempts."
fi
fi
done
121 changes: 121 additions & 0 deletions jenkins/balena-aarch64-alpine-dotnet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version='1.1' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin@1.7.8">
<useBuildBlocker>false</useBuildBlocker>
<blockLevel>GLOBAL</blockLevel>
<scanQueueFor>DISABLED</scanQueueFor>
<blockingJobs></blockingJobs>
</hudson.plugins.buildblocker.BuildBlockerProperty>
<org.jenkins.ci.plugins.html5__notifier.JobPropertyImpl plugin="html5-notifier-plugin@1.5">
<skip>false</skip>
</org.jenkins.ci.plugins.html5__notifier.JobPropertyImpl>
<org.bstick12.jenkinsci.plugins.leastload.LeastLoadDisabledProperty plugin="leastload@3.0.0">
<leastLoadDisabled>false</leastLoadDisabled>
</org.bstick12.jenkinsci.plugins.leastload.LeastLoadDisabledProperty>
<com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty plugin="naginator@1.18.2">
<optOut>false</optOut>
</com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty>
<com.sonyericsson.rebuild.RebuildSettings plugin="rebuild@1.34">
<autoRebuild>false</autoRebuild>
<rebuildDisabled>false</rebuildDisabled>
</com.sonyericsson.rebuild.RebuildSettings>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>BUILD_BRANCH</name>
<defaultValue>master</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
<hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents@2.10">
<maxConcurrentPerNode>0</maxConcurrentPerNode>
<maxConcurrentTotal>0</maxConcurrentTotal>
<categories class="java.util.concurrent.CopyOnWriteArrayList"/>
<throttleEnabled>false</throttleEnabled>
<throttleOption>project</throttleOption>
<limitOneJobWithMatchingParams>false</limitOneJobWithMatchingParams>
<paramsToUseForLimit></paramsToUseForLimit>
<configVersion>1</configVersion>
</hudson.plugins.throttleconcurrents.ThrottleJobProperty>
</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="git@4.14.2">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>git@github.com:balena-io-library/official-images.git</url>
<credentialsId>a2d8eaf4-a373-4efa-a9e3-c331a3687e72</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>${BUILD_BRANCH}</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="empty-list"/>
<extensions/>
</scm>
<assignedNode>base-images</assignedNode>
<canRoam>false</canRoam>
<disabled>true</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers>
<jenkins.triggers.ReverseBuildTrigger>
<spec></spec>
<upstreamProjects>balena-aarch64-alpine</upstreamProjects>
<threshold>
<name>SUCCESS</name>
<ordinal>0</ordinal>
<color>BLUE</color>
<completeBuild>true</completeBuild>
</threshold>
</jenkins.triggers.ReverseBuildTrigger>
<hudson.triggers.TimerTrigger>
<spec>@monthly</spec>
</hudson.triggers.TimerTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>#!/bin/bash

export LIBRARY=&apos;aarch64-alpine-dotnet&apos;

docker login --username=${DOCKERHUB_USERNAME} --password=${DOCKERHUB_PASSWORD}
bash automation/jenkins_build.sh</command>
<configuredLocalRules/>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers>
<hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup@0.44">
<deleteDirs>false</deleteDirs>
<cleanupParameter></cleanupParameter>
<externalDelete></externalDelete>
<disableDeferredWipeout>false</disableDeferredWipeout>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
<org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper plugin="credentials-binding@523.vd859a_4b_122e6">
<bindings>
<org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
<credentialsId>3204255f-7677-4681-9f06-b4a2f804e2a2</credentialsId>
<usernameVariable>DOCKERHUB_USERNAME</usernameVariable>
<passwordVariable>DOCKERHUB_PASSWORD</passwordVariable>
</org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
</bindings>
</org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
<hudson.plugins.build__timeout.BuildTimeoutWrapper plugin="build-timeout@1.25">
<strategy class="hudson.plugins.build_timeout.impl.AbsoluteTimeOutStrategy">
<timeoutMinutes>2880</timeoutMinutes>
</strategy>
<operationList>
<hudson.plugins.build__timeout.operations.AbortOperation/>
</operationList>
</hudson.plugins.build__timeout.BuildTimeoutWrapper>
</buildWrappers>
</project>
121 changes: 121 additions & 0 deletions jenkins/balena-aarch64-alpine-golang.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?><project>
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.plugins.buildblocker.BuildBlockerProperty plugin="build-blocker-plugin@1.7.8">
<useBuildBlocker>false</useBuildBlocker>
<blockLevel>GLOBAL</blockLevel>
<scanQueueFor>DISABLED</scanQueueFor>
<blockingJobs/>
</hudson.plugins.buildblocker.BuildBlockerProperty>
<org.jenkins.ci.plugins.html5__notifier.JobPropertyImpl plugin="html5-notifier-plugin@1.5">
<skip>false</skip>
</org.jenkins.ci.plugins.html5__notifier.JobPropertyImpl>
<org.bstick12.jenkinsci.plugins.leastload.LeastLoadDisabledProperty plugin="leastload@3.0.0">
<leastLoadDisabled>false</leastLoadDisabled>
</org.bstick12.jenkinsci.plugins.leastload.LeastLoadDisabledProperty>
<com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty plugin="naginator@1.18.2">
<optOut>false</optOut>
</com.chikli.hudson.plugin.naginator.NaginatorOptOutProperty>
<com.sonyericsson.rebuild.RebuildSettings plugin="rebuild@1.34">
<autoRebuild>false</autoRebuild>
<rebuildDisabled>false</rebuildDisabled>
</com.sonyericsson.rebuild.RebuildSettings>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>BUILD_BRANCH</name>
<defaultValue>master</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
<hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents@2.10">
<maxConcurrentPerNode>0</maxConcurrentPerNode>
<maxConcurrentTotal>0</maxConcurrentTotal>
<categories class="java.util.concurrent.CopyOnWriteArrayList"/>
<throttleEnabled>false</throttleEnabled>
<throttleOption>project</throttleOption>
<limitOneJobWithMatchingParams>false</limitOneJobWithMatchingParams>
<paramsToUseForLimit/>
</hudson.plugins.throttleconcurrents.ThrottleJobProperty>

</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="git@4.14.2">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>git@github.com:balena-io-library/official-images.git</url>
<credentialsId>a2d8eaf4-a373-4efa-a9e3-c331a3687e72</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>${BUILD_BRANCH}</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="empty-list"/>
<extensions/>
</scm>
<assignedNode>base-images</assignedNode>
<canRoam>false</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers>
<jenkins.triggers.ReverseBuildTrigger>
<spec/>
<upstreamProjects>balena-aarch64-alpine</upstreamProjects>
<threshold>
<name>SUCCESS</name>
<ordinal>0</ordinal>
<color>BLUE</color>
<completeBuild>true</completeBuild>
</threshold>
</jenkins.triggers.ReverseBuildTrigger>
<hudson.triggers.TimerTrigger>
<spec># Run on first Saturday of a month
H H 1-7 * 6</spec>
</hudson.triggers.TimerTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>#!/bin/bash

export LIBRARY='aarch64-alpine-golang'

docker login --username=${DOCKERHUB_USERNAME} --password=${DOCKERHUB_PASSWORD}
bash automation/jenkins_build.sh</command>
<configuredLocalRules/>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers>
<hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup@0.44">
<deleteDirs>false</deleteDirs>
<cleanupParameter/>
<externalDelete/>
<disableDeferredWipeout>false</disableDeferredWipeout>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
<org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper plugin="credentials-binding@523.vd859a_4b_122e6">
<bindings>
<org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
<credentialsId>3204255f-7677-4681-9f06-b4a2f804e2a2</credentialsId>
<usernameVariable>DOCKERHUB_USERNAME</usernameVariable>
<passwordVariable>DOCKERHUB_PASSWORD</passwordVariable>
</org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
</bindings>
</org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
<hudson.plugins.build__timeout.BuildTimeoutWrapper plugin="build-timeout@1.25">
<strategy class="hudson.plugins.build_timeout.impl.AbsoluteTimeOutStrategy">
<timeoutMinutes>2880</timeoutMinutes>
</strategy>
<operationList>
<hudson.plugins.build__timeout.operations.AbortOperation/>
</operationList>
</hudson.plugins.build__timeout.BuildTimeoutWrapper>
</buildWrappers>
</project>
Loading
Loading