Anyone know how to escape spaces in Azure Cli? - azure-devops

I am running
$nameLine= az boards iteration team list --team "DevOpsTesting Team" --timeframe current --project DevOpsTesting | findstr "name"
$nameOnly = (select-string ":(.*)" -inputobject $name).Matches.Groups[1].Value.Replace(",","")
az boards work-item create --title Test --type Task --project DevOpsTesting --iteration DevOpsTesting\\$nameOnly --assigned-to A.B#gmail.com --fields "Description=PR is open, please test the new exe version and approve Priority=2"
But because the value of nameOnly is "Sprint 7" I am getting an error
az : ERROR: unrecognized arguments: 7
At line:4 char:1
..?
thx.

If spaces are used within a iteration, then enclose in double-quotes, in your case you could add the doule-quotes like:
--iteration "DevOpsTesting\\$nameOnly"

Related

How to pass values from csv into az cli deployment as parameters

I don't have much experience with PowerShell and this simple issue has been driving me up the wall. I'm hoping someone can point me in the right direction.
I have a CSV-file with IP-range values
I wish to pass these IP values as a parameter to a Bicep template
The parameter is of type array, see code snippets below
CSV-file:
IP,Comment
10.0.0.1, Comment blabla
10.0.0.52, Comment more blabla
I wish to pass the IP-values into a Azure Bicep template with the following parameter:
param ipArray array
The cli command is as follows:
az deployment group validate -g test-rg -f .\main.bicep -p ipArray=$ipRange
I am unable to populate $ipRange properly. I have tested the following and know it works:
az deployment group validate -g test-rg -f .\main.bicep -p ipArray="['10.0.0.1','10.0.0.52']"
So I need to figure out how to build my Powershell variable according to above syntax
$ipRange = ((Get-Content .\ip_list.csv) | ConvertFrom-Csv).IP
Failed to parse string as JSON:
10.0.0.1 10.0.0.52
Error detail: Extra data: line 1 column 6 (char 5)
Any nudge in the right direction will be greatly appreciated
Thanks!
This code will convert the ip range as you asked for:
$ipRange = ((Get-Content C:\Temp\ip.csv) | ConvertFrom-Csv).IP | ConvertTo-Json
$ipRange = $ipRange.ToString() -replace '"',"'"
$ipRange
one final thing, in your param, it is mentioned as vlkIpArray and in deployment it is mentioned as ipArray. is this a typo error?
param vlkIpArray array and
az deployment group validate -g test-rg -f .\main.bicep -p ipArray="['10.0.0.1','10.0.0.52']"

aqquire localhost.json from azufunction (powershell commands install failed and I found no az-command for cmd.exe) Any Solutions?

I installed last year the powershell az core tools with big problems but got it working.
I used this 2 Commands to get the local.settings.json iwth actual values:
Connect-AzAccount -Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -SubscriptionId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
func azure functionapp fetch-app-settings '<function-name>' --output-file local.settings.json
On installing the powershell core tools we spend a few hours and failed , so i tried to find similar command für standard command line (CMD.exe) but I found no similar command that worked so.
I found only this:
az login --tenant "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx"
this sets the correct tenant and this worked.
I found additionally thsis commad to set the subscription but i got no response:
# change the active subscription using the subscription ID
az account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
And I could request the config setting on screen with that command:
az functionapp config appsettings list --name MyFunctionApp --resource-group MyResourceGroup
But i found no way to create with the az command the local.setings.json and the file is in wrong format so piping it in a file will not work too.
[
...
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"slotSetting": false,
"value": "dotnet"
},
...
]
Can anyone help me to get the file local.settings.json with actual config values with the az commands from standard windows shell.
Generally, local.settings.json file is ignored while publishing to Azure Function App as it is specified in the .gitignore file:
While publishing/deploying the function app, make sure to publish with the setting --publish-local-settings -i.
Syntax:
func azure functionapp publish <FunctionAppName> --publish-local-settings -i
Then, all the local.settings.json config values can be published and the values using the PowerShell cmdlet will be displayed:
Get-AzFunctionAppSetting -Name FunctionAppName -ResourceGroupName RGName | ConvertTo-Json | Out-File "local.settings.json"
OR use the same Az cmdlet to get the correct format of config settings defined in local.settings.json that are published to Azure function app.
to get the file local.settings.json with actual config values
Using az command for saving the published local.settings.json config values in a file:
az functionapp config appsettings list --name MyFunctionApp --resource-group MyResourceGroup --output json > local.settings.json

Not able to set a github environment variable in github actions

My workflow is using a windows runner.
The workflow runs an aws cli command to get instance IDs. I then try to set the returned IDs as a github environment variable to use in future steps
Here is the snippet from my workflow file:
- name: Get IDs
id: get_instances
run: |
$getinfo = aws ec2 describe-instances --filters 'Name=tag:Name,Values=project-bell' --output text --query 'Reservations[*].Instances[*].InstanceId' --region "eu-west-1"
$instances = ($getinfo -Join " ")
echo $instances
echo "INSTANCE_ID=$instances" >> $GITHUB_ENV
- name: Print IDs
run: |
echo {{ env.INSTANCE_ID }}
echo "{{ env.INSTANCE_ID }}"
So the 1st line in my run command of the "Get IDs" step returns the IDs as an array. So $getinfo looks like this:
instanceID 1
instanceID 2
2nd line I use -Join command to get the IDs to be returned in a single line: instanceID 1 instanceID 2
I then try and set this single line as a github environment variable but it isn's working and not sure why.
When i echo $instances i can see that the -Join command has worked and i see the IDs printed as a single line instanceID 1 instanceID 2.
But on the "Print IDs" step {{ env.INSTANCE_ID }} is returned rather than the instanceID 1 instanceID 2 which i tried to set as a github environment variable in the previous step.
Notes:
I have to 2 echos on the "Print IDs" job as i was just testing if i needed quotations for it to work"
I have the -join command because when i tried to set $getinfo (1st run command) as a github env var i got an error saying it was an array
Question
Am I writing the command wrong to set github env?
Or is it something to do with the values themselves - like does it need to be a string?

Migrate(copy) ACR with tag using Import-AzContainerRegistry

I am trying to import Azure container registry with tags.
I know the Azure cli command:
az acr import --name $TARGET_REG --source $SOURCE_REG.azurecr.io/$repo":"$tag;
But Azure cli doesn't support in my work station and need to transform it into Power shell something like:
Import-AzContainerRegistryImage -RegistryName $TARGET_REG -ResourceGroupName $RG_NAME -SourceRegistryUri $SOURCE_REG_URI -SourceImage $tag
Any guidance over there?
After couple of trials and errors I am able to transform it with the below line of code that worked for me:
Import-AzContainerRegistryImage -RegistryName $TARGET_REG -ResourceGroupName $TARGET_RG_NAME -SourceRegistryResourceId $SOURCE_REG_RES_ID -SourceImage $repo:$tag

Updating multiple values of a Azure DevOps variable group from another variable group

I have a requirement which is as follows:
Variable Group A, has 7 set of key=value pairs
Variable Group B, has 7 set of key=value pairs.
In both cases keys are the same, values are only different.
I am asking from the user, the value of be injected in variable group B, user provides me the variable group A name.
Code snippet to perform such update is as below:
export reference_env="Variable Group A"
export target_env="Variable Group B"
values=(addressSearchBaseUrl addressSearchSubscriptionKey cacheUrl calendarApiUrl checkoutBffApiUrl cpCode)
groupId=$(az pipelines variable-group list --group-name "${reference_env}" | jq -r '. [].id')
#grab groupid for further checks later on.
az_create_options=()
for ptr in "${values[#]}"
do
result=$(
az pipelines variable-group list --group-name "${Variable Group ${reference_env}" | jq '.[0].variables.'${ptr}'.value'
)
printf "%s\t%s\t%d\n" "$ptr" "$result" $?
if [[ "$ptr" = "calendarApiUrl" ]]
then
echo "INF: Updating $ptr with new value"
result="https://noname-api.platform.test.com.au/marketing/calendar/v1/AvailableDates/market1/"
insertString=";rev=${target_env}"
lookingfor="v1"
result=$(echo $result| sed s/"${lookingfor}"/"${insertString}"/g)
echo $result
fi
az_create_options+=("$ptr"="$result" )
done
declare -p az_create_options
az pipelines variable-group variable update --group-id 1202 --name "${target_env}" "${az_create_options[#]}"
However, when I run this, I get error as below:
Note: I have masked the values in light of IP but error is the same.
ERROR: unrecognized arguments: addressSearchBaseUrl="https://xxxxxxxxxx" addressSearchSubscriptionKey="yyyyyyyyyyyyyyy" cacheUrl="qqqqqqqqqqqqq" calendarApiUrl=tttttttttttttttt checkoutBffApiUrl="sssssssssssssssss" cpCode="333333"
Can someone guide me please?
You wrongly used update command:
az pipelines variable-group variable update --group-id
--name
[--detect {false, true}]
[--new-name]
[--org]
[--project]
[--prompt-value {false, true}]
[--secret {false, true}]
[--subscription]
[--value]
name is a vairable name. So if you want to update each variable you need to update it one by one.