【问题标题】:Secret variable in Azure devops Pipeline in command line script does not get changed to stars *******命令行脚本中 Azure devops Pipeline 中的秘密变量不会更改为星号 *******
【发布时间】:2021-09-29 00:06:24
【问题描述】:

我正在尝试在 azure 管道中签署一些文件,我已将 .pfx 密码添加为机密并尝试在 - script 命令中使用它,但无论出于何种原因,它似乎都没有被映射。

脚本的相关部分

 - script: 
      $(pathToSignTool) sign /f $(pathToPfx) /p %MAPPEDPASS% Some.vsto
  env:
    MAPPEDPASS: $(pfxPassword)

输出是

生成脚本。
脚本内容:
C:\"Program Files (x86)"\"Windows Kits"\10\bin\10.0.19041.0\x64\signtool.exe sign /f C:\DirWhereThePfxIs\key.pfx /p %MAPPEDPASS% Some.vsto

据我了解,如果映射可以工作,它会变成 **** 而不是留在%MAPPEDPASS%

我也试过 $(MAPPEDPASS)$(env:MAPPEDPASS)$MAPPEDPASS 没有运气。

如何在命令行脚本中映射 Azure devops Pipeline 中的 Secret 变量?

编辑:添加完整的 yaml

# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
- main

pool:
  name: 'XXX Build Pool'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  #change to actual directory where signtool is.
  pathToSignTool: "C:\\\"Program Files (x86)\"\\\"Windows Kits\"\\10\\bin\\10.0.19041.0\\x64\\signtool.exe" 
  #change to actual directory where .pfx is.
  pathToPfx: "C:\\DirWhereThePfxIs\\XXX.pfx" 

steps:
# commented out nuget as we have an issue https://stackoverflow.com/questions/59419416/ignore-nuget-package-restore-on-vdproj-projects-in-azure-pipelines
# but can't use workaround as currently no packages.config exist
#- task: NuGetToolInstaller@1
#
#- task: NuGetCommand@2
#  inputs:
#    command: 'custom'
#    arguments: 'restore YourProjectName\packages.config -PackagesDirectory $(Build.SourcesDirectory)\packages'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- script: 
      $(pathToSignTool) sign /f $(pathToPfx) /p %MAPPEDPASS% XXX.vsto
  env:
    MAPPEDPASS: $(pfxPassword)
    # add actual password to variables (top right corner of this window) as it is 123456 now.

- script: 
      $(pathToSignTool) sign /f $(pathToPfx) /p %MAPPEDPASS% XXX.dll.manifest
  env:
    MAPPEDPASS: $(pfxPassword)

- script: 
      $(pathToSignTool) sign /f $(pathToPfx) /p %MAPPEDPASS% XXX.dll
  env:
    MAPPEDPASS: $(pfxPassword)

 

【问题讨论】:

  • 你能展示完整的任务吗?
  • @vernou 你好,vernou。完成。
  • documentation看来,我们必须做$MY_ENV_VAR才能读取一个环境变量。在你的情况下,这样做:$(pathToSignTool) sign /f $(pathToPfx) /p $MAPPEDPASS Some.vsto.
  • @vernou $MAPPEDPASS 也没有飞。
  • 顺便说一句,您不要双引号路径中的每组空格分隔的子目录,只需将其全部双引号 "\"C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\x64\\signtool.exe\"",它应该解析为 "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\signtool.exe"。跨度>

标签: cmd command-line azure-devops environment-variables azure-pipelines


【解决方案1】:

预计行为不会更改为******,而是保持为%MAPPEDPASS%

【讨论】:

    猜你喜欢
    • 2022-09-23
    • 2019-11-08
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2019-09-18
    相关资源
    最近更新 更多