簡體   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