How can a script access Service Connections Azure Devops Pipelines

0 votes
I can't figure out how to access a Service Connection with a script step in my build pipeline. For example, let's say I have a Service Connection representing credentials for an Azure Service Principal. I'd like to access those credentials in a script step. How can I write a script step that makes use of them?
Apr 2, 2022 in Other DevOps Questions by Kichu
• 19,040 points
895 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Instead of the basic 'Script' (or 'Bash') task use the 'Azure CLI' task. This is for running Az CLI commands, do not run only standard Bash scripts (or PSCore if that's your thing). When you run this task, you'll see a bunch of information about the Service Connection in variables prefixed with 'ENDPOINT_DATA_'. It includes Azure Subscription ID, name, Service Principle Object ID, etc.

Enable the Service Principle details to be added to the environment.  Then it includes the SPN key, TenantID, etc. as secret environment variables.

This is what the task looks like:

- task: AzureCLI@2
  displayName: 'Azure CLI'
  inputs:
    scriptType: bash
    scriptLocation: inlineScript
    azureSubscription: ''
    inlineScript: |
      env | sort

- task: AzureCLI@2
  displayName: 'Azure CLI, with SPN info'
  inputs:
    scriptType: bash
    scriptLocation: inlineScript
    azureSubscription: ''
    addSpnToEnvironment: true
    inlineScript: |
    env | sort
 
This is all only applicable to Azure Cloud Service Connections.
answered Apr 6, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Other DevOps Questions

0 votes
0 answers
0 votes
0 answers
0 votes
0 answers
0 votes
0 answers

How can a traditional SDLC be replaced with DevOps?

Jan 12, 2022 in Other DevOps Questions by Vaani
• 7,070 points
642 views
0 votes
1 answer

How can I preview PowerPoint files in Azure DevOps (VSTS)?

No, there are no viewers for attachments ...READ MORE

answered Feb 9, 2022 in Other DevOps Questions by Bhavitha
• 1,000 points
724 views
0 votes
1 answer
0 votes
0 answers

OWASP Zed Attack Proxy Scan in DevOps pipeline

I want to do the "Authenticated Scan" ...READ MORE

Mar 15, 2022 in DevOps Tools by Kichu
• 19,040 points
935 views
0 votes
1 answer
0 votes
0 answers

Multiple YAML build pipelines in Azure DevOps

Using the new YAML way I want ...READ MORE

Mar 15, 2022 in DevOps Tools by Kichu
• 19,040 points
1,271 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP