I'm using Azure DevOps and their Build and Release pipelines. As part of my build I'd like to delete old files from my Azure Blob storage. I'm using an ubuntu-latest
vmImage.
This task:
- task: AzureCLI@2
displayName: Delete old files
inputs:
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
date=`date -d "1 days ago" '+%Y-%m-%dT%H:%MZ'`
az storage blob delete-batch -s $web --account-name xenobellstorage --if-unmodified-since $date
Produces this error, which doesn't match any params in their documentation.
Script failed with error: Error: Input required: connectedServiceNameARM
If I add azureSubscription: 'Main subscription'
to the task, I get this error, with an Authorize resources button that doesn't work.
There was a resource authorization issue: "The pipeline is not valid. Job Job: Step AzureCLI input connectedServiceNameARM references service connection Main subscription which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz."
The linked page suggests I go to Project Settings to authorize all pipelines, but that toggle doesn't work.
How can I run this AzureCLI task on my Ubuntu VM?
The full YAML file I used that fixed my problem:
# Node.js
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- script: |
grunt --gruntfile gruntfile.js prod
displayName: 'grunt production build'
- task: CopyFiles@2
displayName: 'Copy files'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: |
game/**
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish files'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
- task: AzureCLI@2
displayName: Delete old files
inputs:
azureSubscription: 'Main subscription (abc-123-idd)'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az storage blob delete-batch -s '$web' --account-name mystorage --if-unmodified-since $(date -d "1 days ago" '+%Y-%m-%dT%H:%MZ')