与Jenkins管道阶段交互

时间:2016-10-17 14:37:26

标签: jenkins jenkins-pipeline

是否可以通过脚本(bat或sh)以某种方式与Jenkins管道进行交互?例如。开始新阶段?

echo This is a batch file in no stage
pipeline.stage(build)
echo This is a batch file in build stage

我有一个用PowerShell编写的非常紧凑的构建作业。我的团队现在正在尝试使用Jenkins Pipeline功能,将ps构建代码拆分为阶段(构建核心,构建模块,测试,覆盖等)会很棒。我们可以通过为每个阶段创建函数来轻松实现它,但效率很低(加载ps模块......)

2 个答案:

答案 0 :(得分:1)

我会以另一种方式向你提出建议: 您可以在Powershell脚本中将不同的步骤定义为CmdLet:

function step_1()
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    param ()
    Write-Verbose "step 1"
}
function step_2()
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    param ()
    Write-Verbose "step 2"
}

然后,您可以定义Powershell方法,就像我描述的hier:To call a PowerScript from the Groovy-Script

Groovy管道脚本中:

node ('MyWindowsSlave') {
    stage ('Stage 1') {
        PowerShell(". '.\\all-stages.ps1'; stage1 -Verbose")
    }
    stage ('Stage 2') {
        PowerShell(". '.\\all-stages.ps1'; stage2 -Verbose")
    }
}

您也可以考虑将Groovy Script拆分为多个文件,并让powershell开发人员使用他们自己的Groovy子脚本。

问候。

答案 1 :(得分:0)

您可以使用输入步骤(https://jenkins.io/doc/pipeline/steps/pipeline-input-step/)等待用户响应以继续管道:

简单的“是”或“否”,多重选择,密码确认......

enter image description here

enter image description here

例如,您可以使用ldap组控制谁可以响应此输入事件。