powershell - 如何将一个powershell脚本的输出变量值用于另一个powershell脚本
问题描述
大家好,我正在开发 ymal 发布管道,我有两个 PowerShell 脚本。测试1.ps1 测试2.ps1
步骤 1)在 test1.ps1 中,我使用以下方法设置输出变量:
$link="google.com"
写主机“##vso[task.setvariable variable=packageurl]$link”
第 2 步)现在我想在 test2.ps1 脚本中使用这个 pacakgeurl 变量值。
Ymal 代码如下所示:
- task: AzurePowerShell@3
displayName: 'Query Latest Package'
inputs:
azureSubscription: 'test1'
ScriptType: FilePath
ScriptPath: 'source\test1.ps1'
- task: PowerShell@2
displayName: 'Download package'
inputs:
targetType: filePath
filePath: 'source\test2.ps1'
所以基本上我必须通过 PowerShell 脚本使用从 1 个任务到 2 个任务的输出变量值。
谁可以帮我这个事 ..?
提前致谢。
解决方案
这可以按您的预期工作:
trigger: none
pr: none
pool:
vmImage: 'windows-latest'
steps:
- task: AzurePowerShell@3
displayName: 'Query Latest Package'
inputs:
azureSubscription: 'rg-the-code-manual'
ScriptType: FilePath
ScriptPath: 'stackoverflow\94-variables\script-1.ps1'
azurePowerShellVersion: LatestVersion
- task: PowerShell@2
displayName: 'Download package'
inputs:
targetType: filePath
filePath: 'stackoverflow\94-variables\script-2.ps1'
Yaml 文件就是你所拥有的。
script-1.ps1
设置变量:
$link="google.com"
Write-Host "##vso[task.setvariable variable=packageurl]$link"
并script-2.ps1
使用该变量:
Write-Host $env:PACKAGEURL
推荐阅读
- docusignapi - 我们可以通过 DocuSign API 按收件人 ID 定位签名者吗?
- laravel - Laravel - Laravel 中的 Cron 作业重复错误
- spring - 如何停止在 Spring 或 Spring 批处理中加载配置类(@Configuration)?
- dax - 显示去年同一周的测量结果?
- javascript - 如何在javascript中成对加入数组元素
- sed - sed 在一个字符串上返回多个下一个单词的结果
- javascript - 在select2中添加主题标签有理想的地方吗?
- python - 如何删除最外循环中的文本
- javascript - JavaScript 执行和网络带宽
- google-sheets - 是否有一个公式可以将 2 张纸与特定单词进行比较然后着色?