[英]How to Directly pass parameter to Jenkins Pipeline in shell or powershell files(.sh & .ps1).(Without modifying theirs freestyle configure)
I am now using Gitlab Hook with Jenkins and trying to do some automation test on it. 我现在用Gitlab钩与詹金斯和尝试做一些自动化的测试就可以了。 Now my normal working Build Configure is like this: (Easy sample) 现在,我正常工作的Build Configure就像这样:(简单示例)
./testps.ps1 Hello Secret
And this is the Powershell code: 这是Powershell代码:
$hi = "my age is:"
echo "$($args[0])" $hi "$($args[1])"
The build result: 构建结果:
Hello
my age is:
Secret
Finished: SUCCESS
And so does mostly the same way in building Shell freestyle project. 构建Shell自由式项目的方式几乎相同。
But now I have to run it on pipeline ,but it seems to not work in the same way. 但是现在我必须在管道上运行它,但是似乎不能以相同的方式运行。 here's the way i try(but fail): 这是我尝试的方法(但失败了):
node {
paramAValue = "Hi"
paramBValue = "Wayne"
build job: 'Testps', parameters: [[$class: 'StringParameterValue', name: 'ParamA', value: paramAValue], [$class: 'StringParameterValue', name: 'ParamB', value: paramBValue]]
}
The build result just show nothing :(in pipeline) 构建结果什么也没显示:(在管道中)
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
(nothing here) (这里没有什么)
my age is: 我的年龄是:
(nothing here) (这里没有什么)
Finished: SUCCESS 已完成:成功
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
And also I try something like this: 我也尝试这样的事情:
powershell './testps Hi 123'
Still not work,apparently I didn't learn it well :( 仍然没有用,显然我学得不好:(
Is there anyone know how Directly pass parameter into pipeline job?? 有谁知道如何直接将参数传递给管道作业?
And this is my first quesion here,if there's anything wrong please tell me:D 这是我的第一个问题,如果有什么问题请告诉我:D
You can make use of Powershell Params 您可以使用Powershell参数
Param ( $age, $secret)
Write-Host $age
In the pipeline configure pass 在管道中配置pass
"../test.ps1' -age ${paramAValue} -secret ${paramBValue}"
Not sure if the exact code works. 不确定确切的代码是否有效。 The basic idea is use pass parameter using -parameterName 基本思想是使用-parameterName使用pass参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.