- 1 year ago
Jenkins Azure Blob Storage plugin to copy the contents of Build folder and not build folder to $web azure blob static cotainer
The Jenkins Azure Blob Storage plugin is used to upload files to an Azure Blob Storage container, but by default, it only uploads individual files or entire directories. If you want to copy the contents of a specific folder (not including the folder itself) to the $web
container in Azure Blob Storage, you can use a combination of Jenkins pipeline steps and Azure CLI commands.
Here's a step-by-step guide to achieving this:
Install Azure CLI on Jenkins:
Make sure Azure CLI is installed on your Jenkins server. You can download and install it from the official Microsoft website: https://docs.microsoft.com/en-us/cli/azure/install-azure-cliConfigure Azure Credentials in Jenkins:
Configure your Azure credentials in Jenkins by going to "Manage Jenkins" > "Manage Credentials" > "Global credentials (unrestricted)" > "Add Credentials". Add your Azure service principal credentials, which will be used to authenticate with Azure.Create a Jenkins Pipeline:
Create a Jenkins pipeline for your project, which will include the steps to build and package your application.Add Azure Blob Storage Upload Step:
In your Jenkins pipeline, after the build step, add a step to copy the contents of your build folder to the$web
container in Azure Blob Storage. To do this, use thesh
step to execute Azure CLI commands.For example, the following code snippet assumes you have already built your application, and it's located in the
dist
folder. The Azure Blob Storage container is namedstatic
and is located in the$web
container.groovypipeline {
agent any
stages {
stage('Build') {
steps {
// Your build steps to generate the application in the "dist" folder
}
}
stage('Upload to Azure Blob Storage') {
steps {
// Authenticate with Azure CLI using the Azure service principal credentials
withCredentials([azureServicePrincipal('AZURE_CREDENTIALS_ID')]) {
sh 'az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET --tenant $AZURE_TENANT_ID'
sh 'az storage blob upload-batch --account-name $AZURE_STORAGE_ACCOUNT_NAME --account-key $AZURE_STORAGE_ACCOUNT_KEY --destination $web --source dist'
}
}
}
}
}
In this example, replace
AZURE_CREDENTIALS_ID
,AZURE_CLIENT_ID
,AZURE_CLIENT_SECRET
,AZURE_TENANT_ID
,AZURE_STORAGE_ACCOUNT_NAME
, andAZURE_STORAGE_ACCOUNT_KEY
with the appropriate values from your Azure credentials and Blob Storage account.Trigger the Jenkins Pipeline:
Now, trigger the Jenkins pipeline, and it will build your application and upload the contents of thedist
folder to the$web
container in Azure Blob Storage.
Remember to adjust the code to match your specific build process and folder structure.
By using Azure CLI commands within your Jenkins pipeline, you have more flexibility to perform custom actions, such as copying the contents of a specific folder, before uploading them to Azure Blob Storage.