Skip to content

Latest commit

 

History

History
116 lines (86 loc) · 3.13 KB

set-variables-in-scripts.md

File metadata and controls

116 lines (86 loc) · 3.13 KB
ms.topic ms.service ms.manager ms.author author ms.date
include
azure-devops-pipelines
mijacobs
jukullam
juliakm
02/13/2020

Tip

You can run a script on a:

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)