Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def packagesigner = "Xamarin Public Jenkins (auto-signing) <releng@xamarin.com>"
def oldversion
def newversion
def packagename
def dchcommand
def prevtag
def distributions = DISTRIBUTIONS.tokenize(',')
def sourcebuilders = [:]
def builders = [:]
def alltargets = []
// this should be the same on ALL jobs, it defines the _potential_ distro-arch mapping
def distroarchmap = ['ubuntu-1404': ['amd64','i386','armhf','arm64','ppc64el'], 'ubuntu-1604': ['amd64','i386','armhf','arm64','ppc64el'], 'debian-7': ['amd64','i386','armhf','armel'], 'debian-8': ['amd64','i386','armhf','armel','arm64','ppc64el'], 'raspbian-8': ['armhf']]
for (x in distributions) {
for (y in distroarchmap[x]) {
alltargets << x + "-" + y
}
}
//JENKINS-26481
//def alltargets = distributions.collect {key -> distroarchmap[key].collect{key + "-" + it}}.collectMany { it }
for (x in distributions) {
def mainlabel = x
def strippedlabel = mainlabel.replace('-','')
def label = x + '-' + distroarchmap[x][0]// Need to bind the label variable before the closure - can't do 'for (label in labels)'
sourcebuilders[label] = {
stage("Generate source package for ${mainlabel}") {
node(label) {
step([$class: 'WsCleanup'])
sh "mkdir arbitrary-subdirectory"
dir('arbitrary-subdirectory') {
git credentialsId: 'release-manager', url: PACKAGINGREPO
// dpkg-buildpackage etc need three branches to work - a "debian" branch
// of some kind, an "upstream" branch of some kind, and a "pristine-tar"
// branch of some kind. Clone all three here.
sh "git checkout -t origin/pristine-tar"
sh "git checkout ${SRCMASTER}"
def ORIG = sh(returnStdout: true, script: "pristine-tar list | grep ${packagename}_${newversion}\\.orig\\.tar").trim()
sh "pristine-tar checkout ${ORIG}"
sh "mv ${ORIG} .."
sh "DEBEMAIL=\"${packagesigner}\" dch --distribution=${mainlabel}-${BRANCH} --force-distribution -l +${strippedlabel}b \"Build for ${mainlabel}\""
sh "dpkg-source -b ."
sh "dpkg-genchanges -S -sa > ../`basename ../*.dsc .dsc`_source.changes"
}
sh "ls -l"
stash name: "${mainlabel}", includes: '*.tar*,*.dsc,*.changes'
}
}
}
}
for (x in alltargets) {
def mainlabel = x
def strippedlabel = mainlabel.substring(0,mainlabel.lastIndexOf('-'))
def arch = mainlabel.substring(mainlabel.lastIndexOf('-') + 1)
builders[mainlabel] = {
stage("Building source package for ${strippedlabel} on ${arch}") {
def archallbehaviour = "arch"
if (arch == distroarchmap[strippedlabel][0]) {
archallbehaviour = "all_and_arch"
}
node(mainlabel) {
step([$class: 'WsCleanup'])
unstash "${strippedlabel}"
sh "rm *.changes"
chrootpackage chrootName: "${mainlabel}", sourcePackage: '*.dsc', archAllBehaviour: "${archallbehaviour}"
dir('results') {
stash name: "${mainlabel}", includes: "*.deb,*.changes"
}
}
}
}
}
timestamps {
node(distributions[0] + '-' + distroarchmap[distributions[0]][0]) {
stage("Prepare environment") {
// Wipe workspace
step([$class: 'WsCleanup'])
sh "mkdir arbitrary-subdirectory"
dir('arbitrary-subdirectory') {
// Clone repo
git credentialsId: 'release-manager', url: PACKAGINGREPO
// dpkg-buildpackage etc need three branches to work - a "debian" branch
// of some kind, an "upstream" branch of some kind, and a "pristine-tar"
// branch of some kind. Clone all three here.
sshagent(['release-manager']) {
sh "git checkout -t origin/pristine-tar"
sh "git checkout -t origin/${SRCUPSTREAM}"
sh "git checkout ${SRCMASTER}"
}
// Set git identity
sh "git config user.name \"Xamarin Public Jenkins (auto-signing)\""
sh "git config user.email \"releng@xamarin.com\""
// Get old and new package versions
prevtag = sh(returnStdout: true, script: 'dpkg-parsechangelog | grep ^Version | awk \'{print \$2}\'').trim()
oldversion = sh(returnStdout: true, script: 'dpkg-parsechangelog | grep ^Version | awk \'{print \$2}\' | cut -f1 -d\'-\'').trim()
newversion = sh(returnStdout: true, script: 'basename ${NEWTARBALL} | cut -f2 -d\'-\' | sed \'s/\\.tar\\..*\$//\'').trim()
packagename = sh(returnStdout: true, script: 'dpkg-parsechangelog | grep ^Source | awk \'{print \$2}\'').trim()
}
}
if (oldversion == newversion) {
stage("Checkout release from git") {
dir('arbitrary-subdirectory') {
def ORIG = sh(returnStdout: true, script: "pristine-tar list | grep ${packagename}_${newversion}\\.orig\\.tar").trim()
DCHCOMMAND="-l xamarin \"Packaging bugfix:\""
sh "pristine-tar checkout ${ORIG}"
sh "mv ${ORIG} .."
}
}
} else {
stage("Download and merge new release") {
dir('arbitrary-subdirectory') {
def FILENAME = sh(returnStdout: true, script: "basename ../${NEWTARBALL}").trim()
DCHCOMMAND="-v ${newversion}-0xamarin1 \"New release - `basename ${NEWTARBALL}`\""
sh "wget -O ../${FILENAME} ${NEWTARBALL}"
sh "gbp import-orig --upstream-branch=${SRCUPSTREAM} --debian-branch=${SRCMASTER} --pristine-tar --no-merge --no-interactive ../${FILENAME}"
sh "git merge --strategy-option theirs ${SRCUPSTREAM}"
}
}
}
stage("Tag and push new release to git") {
dir('arbitrary-subdirectory') {
sh "DEBEMAIL=\"${packagesigner}\" dch --distribution=${BRANCH} --force-distribution ${DCHCOMMAND}"
if (oldversion == newversion) {
sh "DEBEMAIL=\"${packagesigner}\" gbp dch --meta --id-length=7 --debian-branch=${SRCMASTER} --since=debian/${prevtag}"
}
sh "git add debian/changelog; git commit -m \"Finalize changelog\""
sh "gbp buildpackage --git-ignore-new --git-tag-only"
sshagent(['release-manager']) {
sh "git push --tags; git push --all"
}
}
}
}
parallel sourcebuilders
parallel builders
node(distributions[0] + '-' + distroarchmap[distributions[0]][0]) {
stage("Publish everything") {
for (x in distributions) {
unstash x
}
for (x in alltargets) {
unstash x
}
sh "ls -l"
step([$class: 'WAStoragePublisher', allowAnonymousAccess: true, cleanUpContainer: false, cntPubAccess: true, containerName: 'specialthings', doNotFailIfArchivingReturnsNothing: false, doNotUploadIndividualFiles: false, doNotWaitForPreviousBuild: false, excludeFilesPath: '', filesPath: '*', storageAccName: 'xamjenkinsartifact', storageCredentialId: 'xxx', uploadArtifactsOnlyIfSuccessful: true, uploadZips: false, virtualPath: 'pipelinepackage2/'])
//build job: 'repo-publish-debian-public-reprepro', parameters: [string(name: 'RELEASE', value: "${BRANCH}"), string(name: 'TRIGGERED_BY', value: "${JOB_NAME}")]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.