0

I am setting the password at the Library in the Azure pipelines under a Variable group.

Now I want to use the password in one of my powershell script by using its variable name from the Library but I am getting error.

Write-Host "Signing of Scripts."
Write-Host $PSScriptRoot
If (Test-Path -Path "C:\DigiCerts\*"){
signtool sign /f C:\DigiCerts\Certificate.pfx /t http://timestamp.sectigo.com /fd SHA256 /p $DigicertsPassword C:\dev\package-scripts\scripts\*.ps1
}
Else {
Write-Host "required certificate not found to sign" -ForegroundColor Red
exit 1
}

So here I am using $DigicertsPassword from the Library under Variable group which I have stored the password.

****Error: DigicertsPassword : The term 'DigicertsPassword' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.+ ... tp://timestamp.sectigo.com /fd SHA256 /p "$(DigicertsPassword)" C:\de ... + CategoryInfo : ObjectNotFound: (DigicertsPassword:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

SignTool Error: Missing filename.****

9
  • use: "$(DigicertsPassword)" Commented Sep 8, 2022 at 11:44
  • @guiwhatsthat Thanks for the reply, I have used "$(DigicertsPassword)" but faced the error, I have edited my question with the error, please check and help Commented Sep 8, 2022 at 12:12
  • Did you used the quotes in the code? Without them PowerShell will not interpret them as string. Commented Sep 8, 2022 at 12:21
  • @guiwhatsthat Yes as you mentioned I have used it with quotes: signtool sign /f C:\DigiCerts\Certificate.pfx /t http://timestamp.sectigo.com /fd SHA256 /p "$(DigicertsPassword)" Commented Sep 8, 2022 at 12:33
  • when you simplify your pipeline and only have a script with the code Write-host "$(DigicertsPassword)" does this print the value which you have defined in the variable group? Commented Sep 8, 2022 at 13:14

1 Answer 1

2

As you confirmed, you are using something like below and it can get the value successfully.

trigger:
- none

pool:
  vmImage: ubuntu-latest
variables:
  - group: xxx #variable group name
steps:
- task: PowerShell@2
  env:
    DigicertsPassword: $(DigicertsPassword)
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      
      Write-Host "$env:DigicertsPassword"

The reason of the issue is secret value need to map, but $key is not a correct way to map.

It has been clarified here:

https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#usage-4

Secrets are not automatically mapped in

By the way, inline script should be able to get the value of runtime variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.