Created
April 5, 2021 13:48
-
-
Save rndazurescript/6a9b6f122f6734cfc4749e9eca9b6236 to your computer and use it in GitHub Desktop.
Deploy Azure DevOps Agent in ACI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger: none | |
variables: | |
ResourceGroup: private-endpoint-demos-rg | |
vnetName: private-endpoint-vnet | |
vnetResourceGroup: $(ResourceGroup) | |
agentSubNetName: agents | |
location: westus2 | |
imageName: azftademo/adoagent:ubuntu-18.04 | |
storageContainerName: 'test' | |
storageAccountName: pepadotest | |
agentPoolName: ephemeraladopool | |
azureSubscription: 'azure-devops-rm-connection-name' | |
aciName: ephemeral-agent | |
aciCpu: 1 | |
aciMemory: 1.5 | |
stages: | |
- stage: Deploy | |
jobs: | |
- job: PrepareAgent | |
displayName: Prepare Agent | |
pool: | |
vmImage: 'ubuntu-latest' | |
steps: | |
- task: AzureCLI@2 | |
name: subnet | |
inputs: | |
azureSubscription: $(azureSubscription) | |
scriptType: pscore | |
scriptLocation: inlineScript | |
inlineScript: | | |
$vnetId= & az network vnet subnet show --resource-group $(vnetResourceGroup) --name $(agentSubNetName) --vnet-name $(vnetName) --query id | |
Write-Output("##vso[task.setvariable variable=id;isOutput=true;]$vnetId") | |
- task: AzureCLI@2 | |
inputs: | |
azureSubscription: $(azureSubscription) | |
scriptType: pscore | |
scriptLocation: inlineScript | |
inlineScript: | | |
az container create --name $(aciName) --resource-group $(ResourceGroup) --location $(location) --image $(imageName) --ip-address private --os-type Linux --cpu $(aciCpu) --memory $(aciMemory) --restart-policy Never --subnet $(subnet.id) --secure-environment-variable AZP_TOKEN="$(System.AccessToken)" --environment-variables AZP_URL="$(System.CollectionUri)" AZP_POOL="$(agentPoolName)" AZP_AGENT_NAME="$(aciName)" | |
- deployment: Deploy | |
environment: 'Production' | |
dependsOn: PrepareAgent | |
displayName: Deploy Files | |
pool: ${{ variables.agentPoolName }} | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- script: date > $(Pipeline.Workspace)/data.txt | |
displayName: 'create dummy file to upload' | |
- task: AzureCLI@1 | |
displayName: 'copy files to container' | |
inputs: | |
azureSubscription: $(azureSubscription) | |
scriptLocation: inlineScript | |
inlineScript: | | |
connectionString=$(az storage account show-connection-string --name $(storageAccountName) --query connectionString --output tsv) | |
echo listing | |
az storage blob list --container-name $(storageContainerName) \ | |
--auth-mode key \ | |
--connection-string "$connectionString" | |
echo "uploading" | |
az storage blob upload-batch --auth-mode key\ | |
--account-name $(storageAccountName) \ | |
--destination $(storageContainerName) \ | |
--source $(Pipeline.Workspace) \ | |
--pattern '*.*' \ | |
--connection-string "$connectionString" | |
- job: DeleteAgent | |
displayName: Delete Agent | |
dependsOn: [Deploy, PrepareAgent] | |
pool: | |
vmImage: 'ubuntu-latest' | |
steps: | |
- script: | | |
echo Container: $(aciName) | |
echo Resource Group: $(ResourceGroup) | |
displayName: Display variables | |
- task: AzureCLI@2 | |
inputs: | |
azureSubscription: $(azureSubscription) | |
scriptType: pscore | |
scriptLocation: inlineScript | |
inlineScript: 'az container delete --name $(aciName) --resource-group $(ResourceGroup) --yes' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment