2017-01-18 14:33:36 +01:00
|
|
|
#!groovy
|
|
|
|
|
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
* that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
* materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-01-25 12:42:22 +01:00
|
|
|
/* Note: the env variables are either Jenkins built-in variables
|
|
|
|
or own variables configured at Manage Jenkins > Configure System */
|
|
|
|
|
2017-01-18 14:33:36 +01:00
|
|
|
properties([
|
|
|
|
[
|
|
|
|
$class : 'BuildDiscarderProperty',
|
|
|
|
strategy: [$class: 'LogRotator', numToKeepStr: '10', artifactNumToKeepStr: '10']
|
|
|
|
],
|
|
|
|
parameters(
|
|
|
|
[
|
|
|
|
stringParam(
|
|
|
|
name: 'XC_BRANDING',
|
|
|
|
defaultValue: 'citrix',
|
|
|
|
description: 'Branding to use. Default value is citrix.'
|
|
|
|
),
|
|
|
|
stringParam(
|
2017-01-23 09:54:31 +01:00
|
|
|
name: 'XC_BRANCH',
|
2017-01-18 14:33:36 +01:00
|
|
|
defaultValue: 'master',
|
|
|
|
description: 'The branch to build. Default value is master.'
|
|
|
|
),
|
|
|
|
booleanParam(
|
|
|
|
name: 'SKIP_CHECKS',
|
|
|
|
defaultValue: false,
|
|
|
|
description: 'Skips initial checks for a faster build. Default value is false.'
|
|
|
|
),
|
|
|
|
booleanParam(
|
|
|
|
name: 'SKIP_TESTS',
|
|
|
|
defaultValue: false,
|
|
|
|
description: 'Skips tests for a faster build. Default value is false.'
|
|
|
|
),
|
|
|
|
booleanParam(
|
|
|
|
name: 'DEV_BUILD',
|
|
|
|
defaultValue: false,
|
|
|
|
description: 'Skips bumping the global build number and uploading the artifacts. Default value is false.'
|
2017-01-23 09:54:31 +01:00
|
|
|
),
|
|
|
|
stringParam(
|
|
|
|
name: 'BUILD_ON_NODE',
|
|
|
|
defaultValue: 'master',
|
|
|
|
description: 'The Jenkins node where to build. Default value is master, but ensure you set it to a node disallowing concurrent builds.'
|
2017-01-18 14:33:36 +01:00
|
|
|
)
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
|
|
|
for (Object key : params.keySet()) {
|
|
|
|
def keyVal = params.get(key)
|
|
|
|
println "Build parameter ${key} set to ${keyVal}"
|
|
|
|
}
|
|
|
|
|
2017-01-23 09:54:31 +01:00
|
|
|
node("${params.BUILD_ON_NODE}") {
|
2017-01-18 14:33:36 +01:00
|
|
|
try {
|
|
|
|
|
|
|
|
stage('Bump build number') {
|
|
|
|
if (params.DEV_BUILD) {
|
|
|
|
println "Running development build. The global build number will not be incremented. The current job's build number will be used."
|
|
|
|
} else {
|
|
|
|
def calcBn = httpRequest httpMode: 'GET',
|
|
|
|
url: "${env.CGI_ENDPOINT}/next-xenadmin?job=${env.JOB_NAME}&number=${env.BUILD_NUMBER}&rev=na&repo=na"
|
|
|
|
|
|
|
|
def nextBn = calcBn.content.trim()
|
|
|
|
println "Got next build number: " + nextBn
|
|
|
|
|
|
|
|
httpRequest httpMode: 'POST',
|
|
|
|
contentType: 'APPLICATION_FORM',
|
|
|
|
requestBody: "nextBuildNumber=${nextBn}",
|
2017-01-30 12:24:21 +01:00
|
|
|
url: "${env.JOB_URL}nextbuildnumber/submit",
|
|
|
|
authentication: 'authentication'
|
2017-01-18 14:33:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Clean workspace') {
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
String GIT_COMMIT_XENADMIN =''
|
|
|
|
|
|
|
|
stage('Checkout sources') {
|
|
|
|
checkout([
|
|
|
|
$class : 'GitSCM',
|
2017-01-23 09:54:31 +01:00
|
|
|
branches : [[name: "refs/heads/${params.XC_BRANCH}"]],
|
2017-01-18 14:33:36 +01:00
|
|
|
extensions : [
|
|
|
|
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'xenadmin.git'],
|
|
|
|
[$class: 'LocalBranch', localBranch: '**'],
|
|
|
|
[$class: 'CleanCheckout'],
|
|
|
|
[$class: 'CloneOption', noTags: false, reference: '', shallow: true]
|
|
|
|
],
|
|
|
|
userRemoteConfigs: scm.userRemoteConfigs
|
|
|
|
])
|
|
|
|
|
|
|
|
GIT_COMMIT_XENADMIN = bat(
|
|
|
|
returnStdout: true,
|
|
|
|
script: """
|
|
|
|
@echo off
|
|
|
|
cd ${env.WORKSPACE}\\xenadmin.git
|
|
|
|
git rev-parse HEAD
|
|
|
|
"""
|
|
|
|
).trim()
|
|
|
|
|
2017-04-28 13:50:16 +02:00
|
|
|
GString BRANDING_REMOTE = "${env.CODE_ENDPOINT}/xs/branding.git"
|
2017-01-18 14:33:36 +01:00
|
|
|
|
2017-04-28 13:50:16 +02:00
|
|
|
def branchExistsOnBranding = bat(
|
|
|
|
returnStatus: true,
|
|
|
|
script: """git ls-remote --heads ${BRANDING_REMOTE} | grep ${params.XC_BRANCH}"""
|
|
|
|
)
|
2017-04-28 15:09:38 +02:00
|
|
|
String branchToCloneOnBranding = (branchExistsOnBranding == 0) ? params.XC_BRANCH : 'master'
|
2017-01-18 14:33:36 +01:00
|
|
|
|
2017-04-28 15:09:38 +02:00
|
|
|
bat """git clone -b ${branchToCloneOnBranding} ${BRANDING_REMOTE} ${env.WORKSPACE}\\branding.git"""
|
2017-04-28 13:50:16 +02:00
|
|
|
|
|
|
|
if (params.XC_BRANDING != 'citrix') {
|
2017-01-18 14:33:36 +01:00
|
|
|
|
|
|
|
println "Overwriting Branding folder"
|
2017-01-25 12:42:22 +01:00
|
|
|
GString BRAND_REMOTE = "${env.CODE_ENDPOINT}/xsc/xenadmin-branding.git"
|
2017-01-18 14:33:36 +01:00
|
|
|
|
|
|
|
def branchExistsOnBrand = bat(
|
|
|
|
returnStatus: true,
|
2017-01-23 09:54:31 +01:00
|
|
|
script: """git ls-remote --heads ${BRAND_REMOTE} | grep ${params.XC_BRANCH}"""
|
2017-01-18 14:33:36 +01:00
|
|
|
)
|
2017-01-23 09:54:31 +01:00
|
|
|
String branchToClone = (branchExistsOnBrand == 0) ? params.XC_BRANCH : 'master'
|
2017-01-18 14:33:36 +01:00
|
|
|
|
|
|
|
bat """
|
|
|
|
git clone -b ${branchToClone} ${BRAND_REMOTE} ${env.WORKSPACE}\\xenadmin-branding.git
|
|
|
|
rmdir /s /q "${env.WORKSPACE}\\xenadmin.git\\Branding"
|
|
|
|
xcopy /e /y "${env.WORKSPACE}\\xenadmin-branding.git\\${XC_BRANDING}\\*" "${env.WORKSPACE}\\xenadmin.git\\Branding\\"
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 18:01:10 +01:00
|
|
|
def CTX_SIGN_DEFINED = bat(
|
|
|
|
returnStdout: true,
|
|
|
|
script: """
|
|
|
|
@echo off
|
2017-03-10 18:07:26 +01:00
|
|
|
if defined CTXSIGN (echo 1) else (echo 0)
|
2017-02-17 18:01:10 +01:00
|
|
|
"""
|
|
|
|
).trim()
|
|
|
|
|
2017-01-18 14:33:36 +01:00
|
|
|
stage('Download dependencies') {
|
2017-04-25 10:22:03 +02:00
|
|
|
GString dotNetFile = GString.EMPTY
|
|
|
|
dotNetFile += (CTX_SIGN_DEFINED == '1') ? 'DOTNET_BUILD_LOCATION_CTXSIGN' : 'DOTNET_BUILD_LOCATION'
|
2017-02-17 18:01:10 +01:00
|
|
|
|
2017-01-30 12:24:21 +01:00
|
|
|
GString remoteDotnet = GString.EMPTY
|
2017-02-17 18:01:10 +01:00
|
|
|
remoteDotnet += readFile("${env.WORKSPACE}\\xenadmin.git\\packages\\${dotNetFile}").trim()
|
2017-01-30 12:24:21 +01:00
|
|
|
GString downloadSpec = GString.EMPTY
|
|
|
|
downloadSpec += readFile("${env.WORKSPACE}\\xenadmin.git\\mk\\deps-map.json").trim().replaceAll("@REMOTE_DOTNET@", remoteDotnet)
|
2017-01-18 14:33:36 +01:00
|
|
|
|
|
|
|
def server = Artifactory.server('repo')
|
|
|
|
server.download(downloadSpec)
|
|
|
|
|
|
|
|
println "Branding for " + params.XC_BRANDING
|
|
|
|
|
|
|
|
if (params.XC_BRANDING == 'citrix') {
|
|
|
|
println "Downloading hotfixes."
|
|
|
|
|
|
|
|
def remoteUrl = server.url
|
2017-01-23 09:54:31 +01:00
|
|
|
String remoteBranch = params.XC_BRANCH
|
2017-01-18 14:33:36 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
httpRequest httpMode: 'GET', url: "${remoteUrl}/builds/xs/hotfixes/${remoteBranch}"
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
println "Hotfixes for ${remoteBranch} not found. Trying trunk instead."
|
|
|
|
httpRequest httpMode: 'GET', url: "${remoteUrl}/builds/xs/hotfixes/trunk"
|
|
|
|
remoteBranch = 'trunk'
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:24:21 +01:00
|
|
|
GString hotFixSpec = GString.EMPTY
|
|
|
|
hotFixSpec += readFile("${env.WORKSPACE}\\xenadmin.git\\mk\\hotfix-map.json").trim().replaceAll("@BRANCH@", remoteBranch)
|
2017-01-18 14:33:36 +01:00
|
|
|
server.download(hotFixSpec)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Create manifest') {
|
|
|
|
GString manifestFile = "${env.WORKSPACE}\\output\\manifest"
|
|
|
|
File file = new File(manifestFile)
|
|
|
|
|
2017-01-23 09:54:31 +01:00
|
|
|
String branchInfo = (params.XC_BRANCH == 'master') ? 'trunk' : params.XC_BRANCH
|
2017-01-18 14:33:36 +01:00
|
|
|
file << "@branch=${branchInfo}\n"
|
|
|
|
file << "xenadmin xenadmin.git ${GIT_COMMIT_XENADMIN}\n"
|
|
|
|
|
2017-04-28 14:26:06 +02:00
|
|
|
def SERVER_BRANDING_TIP = bat(
|
|
|
|
returnStdout: true,
|
|
|
|
script: """
|
2017-01-18 14:33:36 +01:00
|
|
|
@echo off
|
|
|
|
cd ${env.WORKSPACE}\\branding.git
|
|
|
|
git rev-parse HEAD
|
|
|
|
"""
|
2017-04-28 14:26:06 +02:00
|
|
|
).trim()
|
2017-01-18 14:33:36 +01:00
|
|
|
|
2017-04-28 14:26:06 +02:00
|
|
|
file << "branding branding.git ${SERVER_BRANDING_TIP}\n"
|
2017-01-18 14:33:36 +01:00
|
|
|
|
2017-04-28 14:26:06 +02:00
|
|
|
if (params.XC_BRANDING != 'citrix') {
|
2017-01-18 14:33:36 +01:00
|
|
|
def XENADMIN_BRANDING_TIP = bat(
|
|
|
|
returnStdout: true,
|
|
|
|
script: """
|
|
|
|
@echo off
|
|
|
|
cd ${env.WORKSPACE}\\xenadmin-branding.git
|
|
|
|
git rev-parse HEAD
|
|
|
|
"""
|
|
|
|
).trim()
|
|
|
|
|
|
|
|
file << "xenadmin-branding xenadmin-branding.git ${XENADMIN_BRANDING_TIP}\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
//for the time being we download a fixed version of the ovf fixup iso, hence put this in the manifest
|
|
|
|
file << "xencenter-ovf xencenter-ovf.git 21d3d7a7041f15abfa73f916e5fd596fd7e610c4\n"
|
|
|
|
file << "chroot-lenny chroots.hg 1a75fa5848e8\n"
|
|
|
|
|
|
|
|
file << readFile("${env.WORKSPACE}\\scratch\\dotnet-packages-manifest").trim()
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Run checks') {
|
|
|
|
if (params.SKIP_CHECKS) {
|
|
|
|
println "Skipping initial checks on request."
|
|
|
|
} else {
|
|
|
|
|
2017-01-24 14:54:42 +01:00
|
|
|
List<String> list = ["check-roaming.sh", "copyrightcheck/copyrightcheck.sh", "i18ncheck/i18ncheck.sh", "deadcheck/deadcheck.sh", "spellcheck/spellcheck.sh"]
|
2017-01-18 14:33:36 +01:00
|
|
|
for (String item : list) {
|
|
|
|
bat """
|
|
|
|
cd ${env.WORKSPACE}\\xenadmin.git\\devtools
|
|
|
|
sh "${item}"
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Build') {
|
|
|
|
bat """
|
|
|
|
cd ${env.WORKSPACE}
|
|
|
|
sh "xenadmin.git/mk/xenadmin-build.sh"
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Run tests') {
|
2017-01-25 12:42:22 +01:00
|
|
|
|
|
|
|
if (params.XC_BRANDING != 'citrix') {
|
|
|
|
println "Testing package-and-sign script"
|
|
|
|
bat """
|
|
|
|
cd ${env.WORKSPACE}
|
2017-01-30 10:54:19 +01:00
|
|
|
mkdir TestXenAdminUnsigned
|
2017-01-25 12:42:22 +01:00
|
|
|
unzip -q -o output\\XenAdminUnsigned.zip -d TestXenAdminUnsigned
|
|
|
|
sh "TestXenAdminUnsigned/XenAdminUnsigned/mk/package-and-sign.sh"
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2017-01-18 14:33:36 +01:00
|
|
|
if (params.SKIP_TESTS) {
|
|
|
|
println "Skipping tests on request."
|
|
|
|
} else {
|
|
|
|
timeout(time: 60, unit: 'MINUTES') {
|
|
|
|
|
|
|
|
bat """
|
|
|
|
mkdir ${env.WORKSPACE}\\tmp
|
|
|
|
cp -r ${env.WORKSPACE}\\xenadmin.git\\XenAdminTests\\bin\\Release ${env.WORKSPACE}\\tmp
|
|
|
|
cd ${env.WORKSPACE}\\tmp
|
|
|
|
taskkill /f /fi "imagename eq nunit*"
|
|
|
|
echo Starting tests at %time% %date%
|
|
|
|
|
|
|
|
nunit-console /nologo /labels /stoponerror /nodots /process=separate /noshadow /labels /err="${env.WORKSPACE}\\tmp\\error.nunit.log" /timeout=40000 /xml="${env.WORKSPACE}\\tmp\\XenAdminTests.xml" "${env.WORKSPACE}\\tmp\\Release\\XenAdminTests.dll" /framework=net-4.5
|
|
|
|
|
|
|
|
echo Finished tests at %time% %date%
|
|
|
|
cp ${env.WORKSPACE}\\tmp\\XenAdminTests.xml ${env.WORKSPACE}\\output
|
|
|
|
"""
|
|
|
|
|
|
|
|
def text = readFile("${env.WORKSPACE}\\output\\XenAdminTests.xml")
|
|
|
|
assert text.contains('errors="0" failures="0"')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Upload') {
|
|
|
|
if (!params.DEV_BUILD) {
|
|
|
|
dir("${env.WORKSPACE}\\output") {
|
|
|
|
|
|
|
|
if (params.XC_BRANDING == 'citrix') {
|
|
|
|
bat """del /f /q "${env.WORKSPACE}\\output\\XenAdminUnsigned.zip" """
|
|
|
|
}
|
|
|
|
|
|
|
|
def server = Artifactory.server('repo')
|
|
|
|
def buildInfo = Artifactory.newBuildInfo()
|
|
|
|
buildInfo.env.filter.addInclude("*")
|
|
|
|
buildInfo.env.collect()
|
|
|
|
|
2017-01-23 09:54:31 +01:00
|
|
|
GString artifactMeta = "build.name=${env.JOB_NAME};build.number=${env.BUILD_NUMBER};vcs.url=${env.CHANGE_URL};vcs.branch=${params.XC_BRANCH};vcs.revision=${GIT_COMMIT_XENADMIN}"
|
2017-01-18 14:33:36 +01:00
|
|
|
|
|
|
|
String targetSubRepo = (CTX_SIGN_DEFINED == '1') ? 'xenadmin-ctxsign' : 'xenadmin'
|
|
|
|
|
|
|
|
// IMPORTANT: do not forget the slash at the end of the target path!
|
2017-01-23 09:54:31 +01:00
|
|
|
GString targetPath = "xc-local-build/${targetSubRepo}/${params.XC_BRANCH}/${params.XC_BRANDING}/${env.BUILD_NUMBER}/"
|
2017-01-18 14:33:36 +01:00
|
|
|
GString uploadSpec = """ {
|
|
|
|
"files": [
|
|
|
|
{ "pattern": "*", "flat": "false", "target": "${targetPath}", "props": "${artifactMeta}" }
|
|
|
|
]}
|
|
|
|
"""
|
|
|
|
|
|
|
|
def buildInfo_upload = server.upload(uploadSpec)
|
|
|
|
buildInfo.append buildInfo_upload
|
|
|
|
server.publishBuildInfo buildInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentBuild.result = 'SUCCESS'
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
currentBuild.result = 'FAILURE'
|
|
|
|
throw ex as java.lang.Throwable
|
|
|
|
} finally {
|
2017-01-23 09:54:31 +01:00
|
|
|
currentBuild.displayName = "${params.XC_BRANCH}-${params.XC_BRANDING}-${env.BUILD_NUMBER}"
|
2017-01-18 14:33:36 +01:00
|
|
|
step([
|
|
|
|
$class : 'Mailer',
|
|
|
|
notifyEveryUnstableBuild: true,
|
|
|
|
recipients : "${env.XENCENTER_DEVELOPERS}",
|
|
|
|
sendToIndividuals : true])
|
|
|
|
}
|
|
|
|
}
|