How to pass you variable to env in azure devops?

Copper Contributor

How to pass you variable to env in azure devops?
- name: OrganizationName
type: string
- name: AgentPoolName
type: string
- name: ApiVersion
type: string
- name: jobName
type: string

- job: deleteOfflineAgents_${{ parameters.jobName }}
displayName: Delete Offline Agents in ${{ parameters.AgentPoolName }} pool

- script: |
AgentPAT=`aws secretsmanager get-secret-value --secret-id secret --query SecretString --output text | jq -r .secret`
displayName: 'Delete Offline Agents'
ORG_NAME: ${{ parameters.OrganizationName }}
AGENT_POOLNAME: ${{ parameters.AgentPoolName }}
API_VERSION: ${{ parameters.ApiVersion }}

when echo AZURE_DEVOPS_AGENT_PAT shows "$(AgentPAT)"  not the  PAT key  "keysample123asd13"

2 Replies
Hello, if you want to assign to the AZURE_DEVOPS_AGENT_PAT the value of the $(AgentPAT) , please make sure that the $(AgentPAT) --> AgentPAT is part of a variable group, in the pipelines section you have "Library" then you need to create a variable group, and in that variable group you need to create an entry with the AgentPAT value and the pair that is the actual - secret. or link it yo an existing keyvault and reference it like that . and you also need to add that variable group into the pipeline. eg. variable group name : PatTokens
- group: PatTokens

This means you imported the variable group and the variables in that group can no be refferenced as you want and assigned into the pipeline just as your code does above.
Hello @Loredan6,

I think that the value of $(AgentPAT), will be different based on the environment. Do you know how we can load this library dynamically (without having to hardcode the environment in the pipeline) ?

more information in the related ticket :

Thank you for you help