azure devops, bash : 'az pipelines variable-group variable update' - bash

az pipelines variable-group variable update \
--group-id X \
--name ${{parameter.Key}} \
--value ${{parameter.Value}} \
--org $(System.CollectionUri) \
--project $(System.TeamProject)
Is there an option to reach variable-group by name and not by group-id?

have option to reach variable group by name and not by group-id?
The answer is no.
According to the document az pipelines variable-group variable update:
az pipelines variable-group variable update --group-id
--name
[--detect {false, true}]
[--new-name]
[--org]
[--project]
[--prompt-value {false, true}]
[--secret {false, true}]
[--value]
Required Parameters
--group-id --id
Id of the variable group.
--name
Name of the variable.
The group-id is the Required Parameter.

Related

How to open shell with colours using AWS ECS execute-command?

I'm using execute-command to open a shell in a AWS Fargate container:
aws ecs execute-command --cluster MtStack-MyCluster7G3C63FE-D8338439438C \
--task d5d35723871267123672312a \
--interactive \
--command "/bin/bash"
The does not show any colours. Is there a way to enable colours?

Can I add more than one variable to an existing variable group in Azure DevOps?

I have a starter pipeline with one task which is using the Azure CLI: az pipelines variable-group variable create. My whole script looks like this:
steps:
- bash: |
az pipelines variable-group variable create \
--group-id 113 \
--name envName \
--value ${{parameters.envName}} \
--org $(System.CollectionUri) \
--project $(System.TeamProject)
displayName: 'Add variables to group'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
After running this command, the variable now exists in my variable group. However, I was wondering if there was a way to add more than one variable at a time? For example:
steps:
- bash: |
az pipelines variable-group variable create \
--group-id 113 \
--name location \ # First variable
--value ${{parameters.location}} \
--name envName \ # Second variable
--value ${{parameters.envName}} \
--org $(System.CollectionUri) \
--project $(System.TeamProject)
displayName: 'Add variables to group'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
When I run this script with the additional variable, the first variable is overwritten by the next variable. I'm looking into creating a loop that will iterate over all of my parameters to then be passed into my script. Something on the lines of:
steps:
${{each parameter in parameters}}:
- bash: |
az pipelines variable-group variable create \
--group-id 113 \
--name ${{parameter.Key}} \
--value ${{parameters.Value}} \
--org $(System.CollectionUri) \
--project $(System.TeamProject)
displayName: 'Add variables to group'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
This last script gives me A mapping was not expected.
Is there a way to use the script to add more than one variable to an already existing variable group?
Your each is fine, I just fixed small syntax and it works:
parameters:
- name: test1
displayName: test1
type: string
default: "Test-1"
- name: test2
displayName: test2
type: string
default: "Test-2"
jobs:
- job: VG
steps:
- ${{ each parameter in parameters }}:
- bash: |
az pipelines variable-group variable create \
--group-id 113 \
--name ${{parameter.Key}} \
--value ${{parameter.Value}} \
--org $(System.CollectionUri) \
--project $(System.TeamProject)
displayName: 'Add variable ${{parameter.Key}} to group'
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
Results:

get subnet id AWS

i am trying to get the subnet ids within a particular VPC and store them in variables
so I can use them in a bash script
aws ec2 describe-subnets --filter "Name=vpc-id,Values=VPCid" --region $REGION --query "Subnets[*].SubnetId" --output text
and this gives something like this
subnet-12345 subnet-78910
(END)
I wonder how I can store them into a variable.
I tried with
SBnet=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=VPCid" --region $REGION --query "Subnets[*].SubnetId" --output text)
but then I do not know I can access the array/list created.
I tried with
echo $(SBnet[0])
but does not work
I am on MACos usin zsh
You can do this as follows (add your VPC and the region):
#!/bin/bash
SUBNET_IDS=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=vpc-1234" --query "Subnets[*].SubnetId" --output text)
for SUBNET_ID in $SUBNET_IDS;
do
echo $SUBNET_ID
done
To split the list of subnet IDs into variables, you can do this:
#!/bin/bash
SUBNET_IDS=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=vpc-1234" --query "Subnets[*].SubnetId" --output text)
IFS=$'\t ' read -r -a subnet_ids <<< $SUBNET_IDS
echo "${subnet_ids[0]}"
echo "${subnet_ids[1]}"
And the individual subnet IDs will be in the subnet_ids array.
you can do as #jarmod suggested and you could also write a query to extract all the subnets tied to all the VPC's in your system in a comma separated output and use it further like this
aws ec2 describe-subnets --query "Subnets[].[SubnetId,VpcId,CidrBlock,AvailabilityZone]" --output text|sed 's/\t/,/g'

Azure CLI Bash - attaching an app insights resource to api managment

I can create an api management instance
az apim create \
--name "$apimName" \
--resource-group "$resourceGroupName" \
--publisher-name 'Publisher' \
--publisher-email 'Myemail#email.com.au' \
--tags "${resourceTags[#]}"
and I can create an app insights instance
az monitor app-insights component create \
--app "${apimName}-appins" \
--location "australiaeast" \
--resource-group "$resourceGroupName" \
--tags "${resourceTags[#]}"
How do I attach the api insights to api management?
Try the command below, replace the values with yours.
az resource create --resource-type 'Microsoft.ApiManagement/service/loggers' -g '<apim-group-name>' -n '<apim-name>/loggers/<appinsight-name>' --properties '{
"loggerType":"applicationInsights",
"description": null,
"credentials": {
"instrumentationKey": "<Instrumentation-Key-of-your-appinsight>"
},
"isBuffered": true,
"resourceId": "/subscriptions/<subscription-id>/resourceGroups/<appinsight-group-name>/providers/microsoft.insights/components/<appinsight-name>"
}'

passing command from awk to the next command using xargs

I am using AWS EC2 CLI to perform a filter on stopped instances, then create an AMI out of these with the AMI name taken from the instance tag.
aws ec2 describe-instances --output text --profile proj --query 'Reservations[*].[Instances[*].[InstanceId, InstanceType, State.Name, Platform, Placement.AvailabilityZone, PublicIpAddress, PrivateIpAddress,[Tags[?Key==`Name`].Value][0][0]]]' --filter --filters Name=instance-state-name,Values=stopped | awk '{print $1, $8}' | xargs -n2 aws ec2 create-image --profile proj --instance-id {} --name {} --no-reboot
how to let args differentiate the two different parameters from AWK (instnaceid, instance name tag), thereby it can be correctly pumped into the ec2 create-image on the instance-id and --name parameter accordingly
You do not need awk.Using AWS CLI, you are extracting 8 values first and then using awk to extract 2 values from that 8 values. Why? Just extract the 2 values from AWS CLI without using awk.
--query 'Reservations[*].[Instances[*].[InstanceId, [Tags[?Key==`Name`].Value][0][0]]]'
will return only the values you are interested in. Then use xargs to pass the arguments to your next command.
xargs -n2 command --arg1 $1 --arg2 $2
Your entire command becomes:
aws ec2 describe-instances --output text --profile proj --query 'Reservations[*].[Instances[*].[InstanceId, [Tags[?Key==`Name`].Value][0][0]]]' --filter --filters Name=instance-state-name,Values=stopped | xargs -n2 aws ec2 create-image --profile proj --instance-id $1 --name $2 --no-reboot

Resources