An Azure DevOps extension that lets a pipeline step use the URL, username, and password from a Generic service connection without placing those credentials in YAML. AuthenticatedScripts@2 supports pwsh, bash, powershell.exe, and batch (cmd.exe).
Install the task from the Visual Studio Marketplace.
Use a [service connection][serviceConnection] with scripts instead of pasting secrets into variables!
Please note that these tasks are built to only use Generic Service Connections. No other connections will be displayed when configuring these tasks.
See authenticated-scripts for the task source.
- ✅ Supply Generic Service Connection to shell:
Powershell core(pwsh)bash(all platforms, same asBash@3. On Windows usesbashfromPATH, preferring Git Bash)powershell(powershell.exe, Windows only)batch(cmd.exe, Windows only)
- ✅ Shorthand syntax for clean yaml
- ✅ Expose variables mode for using service connection as shared secret
In scriptPath and inlineScript modes, the task makes these environment variables available to the child script:
| Variable | Generic service-connection field |
|---|---|
AS_SC_URL |
URL |
AS_SC_USERNAME |
Username |
AS_SC_PASSWORD |
Password |
Please note that this task does not persist the environment variables for longer than the execution of the script itself.
# Using shorthand
- task: AuthenticatedScripts@2
inputs:
serviceConnection: my-generic-service
bash: curl "$AS_SC_URL" --user "$AS_SC_USER:$AS_SC_PASSWORD"
# Using scriptLocation + scriptType
- task: AuthenticatedScripts@2
inputs:
serviceConnection: my-generic-service
scriptLocation: inlineScript
scriptType: pwsh
inlineScript: |
$password = ConvertTo-SecureString $env:AS_SC_PASSWORD -AsPlainText -Force
$credential = [pscredential]::new($env:AS_SC_USERNAME, $password)
Invoke-RestMethod -Uri $env:AS_SC_URL -Credential $credential
Explicit and shorthand script paths are resolved against the pipeline working directory. Service connection fields are passed through without validation; null or undefined values become empty strings.
scriptPath accepts parameters, which are passed to the script. For bash, like the built-in Bash@3 task, the script runs as exec bash '<scriptFile>' <parameters>, so bash parses the parameters: quoting, $VARIABLE expansion (including $AS_SC_*), and command substitution all work.
Supported scriptType values are pwsh (default), powershell, batch, and bash. batch and powershell are only available on Windows agents. Like Bash@3, bash runs on every agent and uses the first bash on PATH, translating script paths on Windows. On Windows, Git Bash is preferred over WSL's bash.exe, which would not receive the AS_SC_* variables.
For YAML-first pipelines, pwsh, powershell, batch, and bash can replace inlineScript or scriptFile. Specify at most one shorthand.
- task: AuthenticatedScripts@2
inputs:
serviceConnection: my-generic-service
bash: echo "Calling $AS_SC_URL"is the equivalent of
- task: AuthenticatedScripts@2
inputs:
serviceConnection: my-generic-service
scriptType: bash
inlineScript: echo "Calling $AS_SC_URL"You can also use it with scriptLocation: scriptPath:
- task: AuthenticatedScripts@2
inputs:
serviceConnection: my-generic-service
scriptLocation: scriptPath
powershell: scripts/call-service.ps1
parameters: -VerboseIf scriptType is provided, it must match the provided shorthand.
To simply expose the service connection as job variables, use the scriptLocation: createVariables.
This creates SERVICE_API_URL, SERVICE_API_USERNAME, and SERVICE_API_PASSWORD. Username and password are marked secret and are masked in task output.
- task: AuthenticatedScripts@2
inputs:
serviceConnection: my-generic-service
scriptLocation: createVariables
variablePrefix: SERVICE_API
# SERVICE_API_URL, SERVICE_API_USERNAME and SERVICE_API_PASSWORD
# are now available as job secrets
- bash: curl "$SERVICE_API_URL" --user "$HTTP_USER"
env:
HTTP_USER: $(SERVICE_API_USERNAME):$(SERVICE_API_PASSWORD)Variables are job-scoped hence only available to subsequent steps in the same job.
This task is heavily inspired by cloudpups/authenticated-scripts, with ergonomic improvements and update to Node_24 runtime.
This task is available under the MIT license.