繁体   English   中英

如何在Shell或Powershell文件(.sh和.ps1)中直接将参数传递给Jenkins Pipeline。(无需修改其freestyle configure)

[英]How to Directly pass parameter to Jenkins Pipeline in shell or powershell files(.sh & .ps1).(Without modifying theirs freestyle configure)

我现在用Gitlab钩与詹金斯和尝试做一些自动化的测试就可以了。 现在,我正常工作的Build Configure就像这样:(简单示例)

./testps.ps1 Hello Secret

这是Powershell代码:

$hi = "my age is:"
echo "$($args[0])" $hi "$($args[1])"

构建结果:

Hello
my age is:
Secret
Finished: SUCCESS

构建Shell自由式项目的方式几乎相同。

但是现在我必须在管道上运行它,但是似乎不能以相同的方式运行。 这是我尝试的方法(但失败了):


    node {
        paramAValue = "Hi"
        paramBValue = "Wayne"
        build job: 'Testps', parameters: [[$class: 'StringParameterValue', name: 'ParamA', value: paramAValue], [$class: 'StringParameterValue', name: 'ParamB', value: paramBValue]]
    }

构建结果什么也没显示:(在管道中)

Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in C:\Jenkins\workspace\0.Test\scripted pipeline
[Pipeline] {
[Pipeline] build (Building 0.Test » Testps)
Scheduling project: 0.Test » Testps
Starting building: 0.Test » Testps #14

(这里没有什么)

我的年龄是:

(这里没有什么)

已完成:成功

[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

我也尝试这样的事情:

powershell './testps Hi 123'

仍然没有用,显然我学得不好:(

有谁知道如何直接将参数传递给管道作业?

这是我的第一个问题,如果有什么问题请告诉我:D

您可以使用Powershell参数

Param ( $age, $secret)
Write-Host $age

在管道中配置pass

"../test.ps1' -age ${paramAValue} -secret ${paramBValue}"

不确定确切的代码是否有效。 基本思想是使用-parameterName使用pass参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM