简体   繁体   中英

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. Now my normal working Build Configure is like this: (Easy sample)

./testps.ps1 Hello Secret

And this is the Powershell code:

$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.

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

You can make use of Powershell Params

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

In the pipeline configure pass

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

Not sure if the exact code works. The basic idea is use pass parameter using -parameterName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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