Push universal publish artifact via Azure CLI (az artifacts universal publish) - azure

I am using this command:
az artifacts universal publish --organization https://dev.azure.com/project/ --project="myProject" --scope project --feed myFeed --name someName --version 0.0.2 --description "some files" --path .
To upload another package to the feed.
The issue is that I need to update the version every time. is there a way for the command to update it automatically in the next patch?
I know it is possible via the pipeline :
versionOption: 'patch'
Will be great to do the same on the Azure CLI

Direct using Azure CLI publish universial package command to update the version is not supported.
A work around to your demand:
Prepare a local .txt file "C:\temp\File.txt" contains the initial version value "0.0.1".
Use the following PowerShell command to update the version every time.
$file = "C:\temp\File.txt"
$fileVersion = [version](Get-Content $file | Select -First 1)
$newVersion = "{0}.{1}.{2}" -f $fileVersion.Major, $fileVersion.Minor, ($fileVersion.Build + 1)
$newVersion | Set-Content $file
And use the value of newVersion in your Azure CLI command.
Here is the sample:
az artifacts universal publish --organization https://dev.azure.com/project/ --project="myProject" --scope project --feed myFeed --name someName --version $newVersion --description "some files" --path .

Related

Zip-deploy Azure functions while public access is disabled (access regstrictions are in place)

I disabled Allow public access on an Azure Function App for security reasons:
However after that, zip deploys from Visual Studio (publish functionality) and via Github Actions fail, as also the API for deployment isn't publicly reachable anymore. In that case, how would one zip deploy updated Azure functions?
If you need ZIP deployment, you need to deploy the code from inside the VNET to the private endpoint of the AppService. For GitHub Actions, this means deploying a self-hosted runner on a VM inside the VNET to push the new code to AppService. There is an example for Azure DevOps self-hosted agents.
As an alternative, you can publish your ZIP to a storage account and let the function pull the new application code to run. There is also a full example including GitHub Actions.
The most relevant quotes from the second example are:
This article shows how to deploy to a Private Endpoint-enabled site from a Continuous Integration pipeline (such as GitHub Actions, Circle CI, Jenkins, or Travis CI) without having to self-host the CI service on a VM. Since Private Endpoints disables all inbound traffic from the internet, our CI pipeline will publish the files to a storage account and give the web app a SAS URL to files. Once the web app is given this SAS URL, it will pull the files from the storage account.
- name: Set SAS token expiration
run: echo "expiry=`date -u -d "$EXPIRY_TIME" '+%Y-%m-%dT%H:%MZ'`" >> $GITHUB_ENV
- name: Azure CLI script
uses: azure/CLI#v1
with:
azcliversion: 2.19.1
inlineScript: |
az extension add --name webapp
az storage account create -n $ACCOUNT -g $GROUP -l westus
az storage container create -n $CONTAINER --account-name $ACCOUNT
az storage blob upload -f app.zip --account-name $ACCOUNT -c $CONTAINER -n $ACCOUNT
ZIP_URL=$(az storage blob generate-sas --full-uri --permissions r --expiry ${{ env.expiry }} --account-name $ACCOUNT -c $CONTAINER -n $ACCOUNT | xargs)
az webapp deploy --name $WEBAPP --resource-group $GROUP --type zip --src-url $ZIP_URL --async false
az storage container delete -n $CONTAINER --account-name $ACCOUNT

Deploy or publish Asp.Net Core 6.0 Web Job Zip file on Azure App service (Window Instance) using AZURE CLI

I want to Deploy or publish my Asp.Net Core 6.0 Web Job (Continuous) project Zip file on Azure App service (Window Instance) using AZURE CLI
I want it to deploy using AZURE CLI Commends only
Here is the Syntax of Azure CLI for publishing/deploying the Web Job to the Azure App Service:
dotnet publish --configuration Release -o .deploy/app_data/Jobs/Continuous/pgp
cp run.cmd .deploy/app_data/Jobs/Continuous/pgp
cd .deploy ; zip -r ../deploy.zip . * ; cd ..
az webapp deployment source config-zip -g $AZURE_RESOURCE_GROUP -n $AZURE_APP_SERVICE --src ./deploy.zip
From your current working directory location, you have to run these commands.
Example:
Note: run.cmd file consists of the command called dotnet MyWebJob.dll %*
dotnet publish src --configuration Release -o '../_zip/app_data/Jobs/Continuous/MyWebJob'
copy ./run.cmd './_zip/app_data/Jobs/Continuous/MyWebJob'
Compress-Archive -Path ./_zip/* -DestinationPath ./deploy.zip -Force
az webapp deployment source config-zip -g mywebjobapp-rg -n mywebjobapp --src ./deploy.zip

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

Migrating Gitlab Container Registry To Azure Contaner Registry

I am trying to migrate Gitlab-ce Container Registry to Azure Container Registry :
the command im using :
az acr import \
--name acr name\
--source gitlab/repo/repo/tag
--username ****\
--password *****
and it works.
what im trying to do now since there is no direct migration in the internet is to create a script to automate the migration process
my idea is like this :
# Get list of projects,repos and tags
repos = i couldn't find a command to list the repos
for project in project do:
repos = get all repos
for repo in repos do:
tags = get all tags
az acr import \
--name acr name\
--source gitlab/$project/$repo/$tag
--username ****\
--password *****
done
done
The Problem is i couldn't find any command to list project,repos or tags using gitlab command line
is there another way to automate the migration if i couldn't find the commands ??
Please check if below commands can give an idea to work around:
Here we try to use the Azure CLI commands az acr repository list and az acr repository show-tags to include image tags in a loop.
SOURCE_REGISTRY=myregistry
TARGET_REGISTRY=targetregistry
# Get list of source repositories
REPOS = $(az acr repository list \ --name $SOURCE_REGISTRY --output tsv)
# Enumerate tags and import to target registry
for repo in $REPOS; do
TAGS= $(az acr repository show-tags --name $OURCE_REGISTRY --repository $repo --output tsv);
for tag in $TAGS; do
echo "Importing $repo:$tag";
az acr import --name $TARGET_REGISTRY --source $SOURCE_REGISTRY /$repo":"$tag --username <username> --password <password> ;
done
done
also please check the Azure PowerShell equivalents as in Reference: Microsoft Docs and almost similar to Stack Overflow thread
References:
Moving docker images from one container registry to another | by Paulo Gomes | Medium
container-registry-import-images | Microsoft Docs

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

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]

Resources