VSTS 将变量传递到 Azure PowerShell 脚本参数

编程入门 行业动态 更新时间:2024-10-28 14:26:07
本文介绍了VSTS 将变量传递到 Azure PowerShell 脚本参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个 Azure PowerShell 任务,我想在其中传递变量.目前我正在使用脚本参数传递变量,如截图所示:

I have multiple Azure PowerShell tasks in which I'd like to pass variables. Currently I'm passing variables with Script Arguments, like on the screenshot:

脚本参数的问题在于,如果有更改,我必须在每个进程中对其进行编辑.是否有可能只有一个变量可以链接到多个进程?我看过 VSTS:将构建变量传递到 Powershell 脚本任务 但无论我如何编辑我的脚本,他们都拒绝工作.该主题也没有解释是否应该将变量放入流程变量或队列构建变量中.这是我试图自动化的脚本:

The problem with Script Arguments is that I'd have to edit them in every process if there is a change. Is it possible to have just a single variable that I can link to multiple processes? I've looked at VSTS: Pass build variables into Powershell script task but no matter how I edit my scripts they refuse to work. That topic also doesn't explain if variables should be put into process variables or Queue Build Variables. Here is the script that I'm trying to automate:

    param
(
    [Parameter(Mandatory)]
    [String]$NewFileLocation1
)

Set-AzureRmVMCustomScriptExtension -Argument "-NewFileLocation1 $NewFileLocation" -ResourceGroupName Test-RG1`
    -VMName VM1 `
    -Location northeurope `
    -FileUri https://raw.githubusercontent/x/assets/master/PowerShell/PS1/PS1/PS1.ps1 `
    -Run 'PS1.ps1' `
    -Name PS1

PS1.ps:

    param
(
    [Parameter(Mandatory)]
    [String]$NewFileLocation

)
New-Item $NewFileLocation

推荐答案

这是我正在使用的:

Param (
    [string]$location = $env:location,
    ...
    [string]$tagEnvironment = $env:tagEnvironment
)

我正在使用 VSTS 库变量组,您可以将变量组链接到不同的发布管道.

I'm using VSTS Library Variable groups, you can link variable groups to different release pipelines.

这篇关于VSTS 将变量传递到 Azure PowerShell 脚本参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 09:42:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/801386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   脚本   参数   VSTS   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!