How do you download a build artifact using Azure Devops CLI? - azure

I got this far using scoop install azure-cli
az extension add -n azure-devops
az devops login
But I am not sure what to do next. I am looking for something like this to output the contents of a file to stdout
az pipeline build get_artifact --project-id=xxx --name=myCI --artifact=drop --path=docker-compose.yml -o -

Please check this:
az pipelines runs artifact download --artifact-name
--path
--run-id
[--detect {false, true}]
[--org]
[--project]

Related

Azure cli command for deploying react.js code to node Azure App Service

The commands for deploying the zip file are clear, but it's unclear to me what the process would be for creating the appropriate zip file for a node project. Any help with this would be much appreciated. Here are some commands I've tried: az webapp deployment source config-zip -n <app-name> -g <app-group> --src upload.zip az webapp deploy -n <app-name> -g <app-group> --src-path ./build
az webapp deploy
If you are using az webapp deploy for continuous Zip Deployment you have to add the SCM_DO_BUILD_DURING_DEPLOYMENT=true config either manually in a portal or using cli command az webapp config appsettings set
# To set config to enable build automation for ZIP deploy
az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
az webapp deployment
If you use az webapp deployment the kudu zip push deployment for a web app deployment.
Kudu thinks that zip deployments do not require any build-related tasks such as npm install or dotnet publish by default. To enable Kudu detection logic and the build script creation process, include a .deployment file in your zip file with the following content: [config] SCM DO BUILD DURING DEPLOYMENT = true
If you want to use ZIP deployment for enable the build automation you can have to set the config
SCM DO BUILD DURING DEPLOYMENT = true.
Refereces
az web deploy
az web deployment

Publish Multiple Bicep Templates to a Container Registry

We are in the process of transitioning our infrastructure from using ARM templates to Bicep templates. We have a dedicated repository with all of our template files which we wish to publish to a central repository to be used by other repos in our organization.
Previously with ARM templates, we published the folder that contained all of our templates to an Azure Storage account, that could then be referenced by others repo using the template blob url with a SAS token. We are looking to do something with bicep templates so we do not need to publish each one individually. Currently the az cli and powershell command only contain the ability to publish one file at a time using the --file argument:
az bicep publish --file storage.bicep --target br:exampleregistry.azurecr.io/bicep/modules/storage:v1
The only possibility I see is using a foreach statement in powershell that iterates through each file in the folder and publishes individually:
foreach ($file in Get-ChildItem)
{
az bicep publish --file $file.name --target br:exampleregistry.azurecr.io/bicep/modules/$filename:$version
}
Question:
Has anyone come up with a more optimized way in which to publish multiple bicep templates in a single operation?
AFAIK the way you did seems to be the way to publish multiple bicep
templates to acr which iterates through each bicep file.
You can also check this Automate Maintaining a Private Bicep Module
Registry with Azure Pipelines where already published ones are
compared to the bicep files in folder and only non existing ones are published to the registry every time.
Here the ACR is used to create a private Bicep registry for sharing
modules and a build pipeline is used to publish modules into the ACR
when new modules are added or existing ones are modified or changed.
I had some trouble to make it work with the foreach loop. The following code worked for me:
azure-pipelines.yml:
jobs:
- job: modules
displayName: 'Publish Bicep Modules'
pool:
name: 'myBuildingPoolName'
steps:
- task: AzureCLI#2
displayName: 'Publish/Update Modules to Registry'
inputs:
azureSubscription: $(ServiceConnectionName) # Pipeline paramater
scriptType: 'pscore'
scriptLocation: inlineScript
inlineScript: |
az bicep install
$registryName = '$(RegistryName)' # Pipeline paramater
$version = '$(Version)' # Pipeline paramater
# bicep files are in the modules folder
$modules = Get-ChildItem -Path ./Modules/*.bicep -Recurse -Include *.bicep
foreach ($module in $modules){
$moduleName = $module.BaseName.ToLower()
Write-Host "Adding new module ${moduleName} with version $version"
az bicep publish --file $module.FullName --target br:${registryName}.azurecr.io/bicep/modules/${moduleName}:${version}
}
Also make sure you have Azure CLI & Powershell installed in case you use a self hosted docker AgentPool:
Dockerfile:
#Install Azure-CLI
RUN curl -LsS https://aka.ms/InstallAzureCLIDeb | bash \
&& rm -rf /var/lib/apt/lists/*
#Install Powershell
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update
RUN add-apt-repository universe
RUN apt-get install -y powershell
Bicep templates are text files, so one alternative to an ACR is to simply store the templates in a code repository.
Advantages include:
storing the templates is very easy, with as much control as you would like using branches and pull requests.
controlling access to the templates is easy; you allow your consumers read-access to the repository
using the templates is very easy; your consumers can just check out the code repository and reference the template they need by a relative file path

Az acr build command info needed

As per the documentation https://learn.microsoft.com/en-us/azure/container-registry/container-registry-quickstart-task-cli the below command builds and pushes to registry. What if I need only build and then push based on my interest .Because I have to scan image before pushing it.
az acr build --image sample/hello-world:v1
--registry myContainerRegistry008
--file Dockerfile .
Note: There is no docker daemon installed on the system.
As suggested in the Azure Documentation ,You can use --no-push flag in the az acr build command to build the docker file & not to push it to the registry,
Here is the sample output for reference :

Azure az cli Docker Hub Web App ressource configuration

I'm trying to setup a script for automate the creation of a new environment for my app, and i need a docker webapp.
The problem is that i need to pull the image from docker hub.
When i create an env from the interface in juste setup it like that :
The problem is that i don't find out how i can configure the "Source de registre" on Docker Hub by the az cli.
For now the command i'm using to create a new web app ressource is this one
az webapp create -g name_of_group -p name_of_plan -n resource-test2 -i https://registry.hub.docker.com/publisher/name_of_image:version -s name_of_image -w my_password
The problem of this command is that it give me this configuration
Which doesn't work because i can't get logged in (probably because it's not configured as a Docker Hub registre).
Do you know how i can specify this configuration in my az cli command ? Thanks
To deploy the images stored in a private registry or the Docker Hub, you can set the environment variables below:
DOCKER_REGISTRY_SERVER_USERNAME - The username for the ACR server.
DOCKER_REGISTRY_SERVER_URL - The full URL to the ACR server. (For example, https://my-server.azurecr.io.)
DOCKER_REGISTRY_SERVER_PASSWORD - The password for the ACR server.
Get more details here. And you can use the CLI command az webapp config appsettings set to do it.
Recently had the same problem deploying azure cloud webapp from a container in my private docker hub repo. UI experience works fine but when I do it using azure cli with 'az webapp create ...' ended up with same problem. I was able to fix it by using 'az webapp config container set ...' command after creating the webapp. See below and in my github repo
# First create the webapp with a docker container:
~$ az webapp create -n $webAppName -g $resGroup -p $servicePlan -i $containerImg -s $dockerUsr -w $dockerPass --tags Lifecycle=Test
# Update docker container settings with your private docker hub repo credentials:
~$ az webapp config container set --name $webAppName --resource-group $resGroup --docker-custom-image-name 'DOCKER|dockeruser/myrepo:tweb1' --docker-registry-server-url 'https://index.docker.io/v1' --docker-registry-server-user 'dockeruser' --docker-registry-server-password 'xxxxxxxxxxx'

Deploy gitlab artifact to microsoft azure web app using azure cli

Is it possible to deploy artifacts generated by GitLab with azure cli.
# Deploy sample code to "staging" slot from GitHub.
az webapp deployment source config --name $webappname --resource-group myResourceGroup \
--slot staging --repo-url $gitrepo --branch master --manual-integration
similar to this but only artifacts not the whole repository
For now, Azure Cli 2.0 supports to deploy webapp from Git or or Mercurial repositories. Currently, Gitlab is not supported.
Group
az webapp deployment source: Manage source control systems.
Commands:
config : Associate to Git or Mercurial repositories.
You could deploy your webapp using manual steps. Please refer to this link:Setting up continuous deployment using manual steps.

Resources