| ms.topic | include |
|---|---|
| ms.service | azure-devops-pipelines |
| ms.manager | mijacobs |
| ms.author | jukullam |
| author | juliakm |
| ms.date | 02/13/2020 |
Tip
You can run a script on a:
- Windows agent using either a Batch script task or PowerShell script task.
- macOS or Linux agent using a Shell script task.
Batch script
:::image type="icon" source="../../tasks/utility/media/batch-script.png" border="false"::: Set the sauce and secret.Sauce variables
@echo ##vso[task.setvariable variable=sauce]crushed tomatoes
@echo ##vso[task.setvariable variable=secret.Sauce;issecret=true]crushed tomatoes with garlic:::image type="icon" source="../../tasks/utility/media/batch-script.png" border="false"::: Read the variables
Arguments
"$(sauce)" "$(secret.Sauce)"
Script
@echo off
set sauceArgument=%~1
set secretSauceArgument=%~2
@echo No problem reading %sauceArgument% or %SAUCE%
@echo But I cannot read %SECRET_SAUCE%
@echo But I can read %secretSauceArgument% (but the log is redacted so I do not spoil
the secret)PowerShell script
:::image type="icon" source="../../tasks/utility/media/powershell.png" border="false"::: Set the sauce and secret.Sauce variables
Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"
Write-Host "##vso[task.setvariable variable=secret.Sauce;issecret=true]crushed tomatoes with
garlic":::image type="icon" source="../../tasks/utility/media/powershell.png" border="false"::: Read the variables
Arguments
-sauceArgument "$(sauce)" -secretSauceArgument "$(secret.Sauce)"
Script
Param(
[string]$sauceArgument,
[string]$secretSauceArgument
)
Write-Host No problem reading $env:SAUCE or $sauceArgument
Write-Host But I cannot read $env:SECRET_SAUCE
Write-Host But I can read $secretSauceArgument "(but the log is redacted so I do not
spoil the secret)":::image type="icon" source="../../tasks/utility/media/shell-script.png" border="false"::: Set the sauce and secret.Sauce variables
#!/bin/bash
echo "##vso[task.setvariable variable=sauce]crushed tomatoes"
echo "##vso[task.setvariable variable=secret.Sauce;issecret=true]crushed tomatoes with garlic":::image type="icon" source="../../tasks/utility/media/shell-script.png" border="false"::: Read the variables
Arguments
"$(sauce)" "$(secret.Sauce)"
Script
#!/bin/bash
echo "No problem reading $1 or $SAUCE"
echo "But I cannot read $SECRET_SAUCE"
echo "But I can read $2 (but the log is redacted so I do not spoil the secret)"Console output from reading the variables:
No problem reading crushed tomatoes or crushed tomatoes
But I cannot read
But I can read ******** (but the log is redacted so I do not spoil the secret)