在Azure DevOps中使用从一个PowerShell任务到另一个任务的变量值 [英] use variable value from one PowerShell task to another in Azure Devops

查看:0
本文介绍了在Azure DevOps中使用从一个PowerShell任务到另一个任务的变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理脚本,希望从第一个脚本中获取结果并相应地运行第二个脚本。

这是我的第一个脚本-

$result = <command 1>

if($result)

{

< run command 2>


return $true

}

else 
{

return 
$false

}

这是第二个脚本

if($return -eq $true)

{

<run Command 3>

}

else{

<run command 4>
 
}

我在Azure DevOps中有两个独立的任务来执行这两个脚本。

我正在流水线中使用Azure PowerShell任务和输出变量-返回

QUE-First脚本运行良好。它返回True或False值,但第二个脚本不起作用。它只是预置Else条件,即从第一个脚本返回值是真还是假。 如何根据第一个脚本返回的真假结果使第二个脚本工作

推荐答案

因为它们是两个独立的任务,您需要设置一个变量来保存第一个脚本结果,然后可以在第二个任务中使用该值。

以下是在Azure DevOps中设置变量的脚本:

echo "##vso[task.setvariable variable=variablename;]value"

您可以将此脚本添加到If statement

举个例子:

Azure PowerShell任务%1

$result = command 1

if($result)

{

 echo "##vso[task.setvariable variable=testvar;]$true"    
   return $true
    
}

else {

    echo "##vso[task.setvariable variable=testvar;]$false"    
    return $false 

}

在此脚本中,它将根据条件创建一个管道变量。然后,在第二个PowerShell任务中,您可以使用$variablename获取它。

Azure PowerShell任务2

例如:

if($testvar = $true)

{
   <run Command 3>
}

else{

<run command 4>

}

这篇关于在Azure DevOps中使用从一个PowerShell任务到另一个任务的变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆