Just thought I'd drop in and describe where we ended up with this. It works for us, YMMV.
This is running in the context of a Jenkins deploy run, but the concepts should apply to most other use cases.
There are a lot of env vars floating around in all of this; i know it's not ideal, but it's really the easiest way to move values around in Jenkins without going crazy with OO classes that are really hard to get working in the Jenkins context. I have recently come up with a pattern to store more complex objects in env vars as json strings, and convert them when needed.
Happy to answer any questions from anyone interested in using this admittedly obscure functionality.
// this is called from vars/deploy.groovy when appropriate
clickOnceDeploy([clickAppName:env.clickOnceName, clickAppPath:env.clickOnceDir, targetEnv:targetMap.key])
// defined in vars/deploy.groovy
def clickOnceDeploy(HashMap clickParms) {
// find the zip in the download folder
String dlFolder = "${WORKSPACE}/${env.packageDownloadDir}"
String clickOncePackage = "${dlFolder}/${env.releasePath}/${clickParms.clickAppPath}.zip"
String targetEnv = clickParms.targetEnv
String zipFileName = "${clickOncePackage.replace('.zip', '')}-${targetEnv}.zip"
// extract the zip - select the target env folder
unzip zipFile: clickOncePackage, glob: "${targetEnv}/**", quiet: true
// zip that folder up, use powershell to get the dir included
pwsh "Compress-Archive -Path ${targetEnv} -DestinationPath ${zipFileName} -Force"
// publish it to proget asset dir
HashMap publishParams = [assetDir:"${clickParms.clickAppName}", zipFilePath:zipFileName]
addToInfoMessages("Publishing ClickOnce App: ${clickParms.clickAppName}/${targetEnv}")
publish.publishProGetAssetFromZip(publishParams)
// defined in vars/publish.groovy
def publishProGetAssetFromZip(HashMap publishParams) {
// check for required params
assert publishParams.assetDir != null
assert publishParams.zipFilePath != null
// sane defaults
publishParams.get('progetBase', env.progetUrl)
publishParams.get('overwrite', true)
publishParams.get('format', 'zip')
// build the api endpoint
String progetAssetImportApi = "endpoints/${publishParams.assetDir}/import/?format=${publishParams.format}&overwrite=${publishParams.overwrite.toString()}"
String assetUrl = "${publishParams.progetBase}/${progetAssetImportApi}"
// need to pass the api token, so pull it from the jenkins cred store
withCredentials([string(credentialsId: 'proget-api-key', variable: 'token')]) {
retry(3) {
httpRequest httpMode: 'POST',
url: assetUrl,
uploadFile: publishParams.zipFilePath,
customHeaders: [[maskValue: true, name: 'X-APIKey', value: token]],
ignoreSslErrors: true,
responseHandle: 'NONE',
contentType: 'APPLICATION_OCTETSTREAM',
wrapAsMultipart: false,
quiet: true
}
}
addToInfoMessages("Published to ${publishParams.progetBase}/assets/${publishParams.assetDir}")
}