upload artifact to azure cdn
pipeline {
agent any
environment {
AZURE_SUBSCRIPTION_ID='99999999-9999-9999-9999-999999999999'
AZURE_TENANT_ID='99999999-9999-9999-9999-999999999999'
AZURE_STORAGE_ACCOUNT='myStorageAccount'
}
stages {
stage('Build') {
steps {
sh 'rm -rf *'
sh 'mkdir text'
sh 'echo Hello Azure Storage from Jenkins > ./text/hello.txt'
sh 'date > ./text/date.txt'
}
post {
success {
withCredentials([usernamePassword(credentialsId: 'azuresp',
passwordVariable: 'AZURE_CLIENT_SECRET',
usernameVariable: 'AZURE_CLIENT_ID')]) {
sh '''
echo $container_name
# Login to Azure with ServicePrincipal
az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID
# Set default subscription
az account set --subscription $AZURE_SUBSCRIPTION_ID
# Execute upload to Azure
az storage container create --account-name $AZURE_STORAGE_ACCOUNT --name $JOB_NAME --auth-mode login
az storage blob upload-batch --destination ${JOB_NAME} --source ./text --auth-mode login
# Logout from Azure
az logout
'''
}
}
}
}
}
}