1

Is it possible to somehow interact with the Jenkins Pipeline from the script (bat or sh)? E.g. to initiate new stage?

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

I have a pretty compact build job written in PowerShell. My team is now experimenting with the Jenkins Pipeline feature and it would be great to split our ps build code to stages (build core, build modules, test, coverage and so on). We could easily do it by creating function for every stage but it would be inefficient (loading ps modules...)

honzajscz
  • 2,850
  • 1
  • 27
  • 29
  • 1
    This is not intended from a Jenkins Pipeline if I understand it correctly. The pipeline Jenkins file is supposed to control and contain the general flow of your build by creating stages/nodes etc. Reversing this so the pipelines flow is in a script does not seem intended to me. Splitting your script into parts and running them sequentially on a single node seems like the way to go in your case to me. – Bricktop Oct 17 '16 at 15:38
  • I was expecting this answer. Thx anyway! – honzajscz Oct 18 '16 at 07:59

2 Answers2

1

I would propose you another way: you may define your different steps as CmdLet in your Powershell script:

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

Then, you can define the Powershell method, like I describe hier: To call a PowerScript from the Groovy-Script

In your Groovy pipeline-script:

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

You may also consider to split your Groovy Script in several files, and let the powershell developer using they own Groovy sub-script.

Regards.

Community
  • 1
  • 1
elou
  • 1,242
  • 15
  • 21
  • 1
    This is what I ended up using. The disadvantage of this approach is that it starts a new process for every single stage. This makes e.g. variable sharing harder. – honzajscz Mar 04 '17 at 07:53
0

You can use the input step (https://jenkins.io/doc/pipeline/steps/pipeline-input-step/) to wait a user response to continue the pipeline:

A simple 'yes' or 'no', a multiple choosen, a password confirmation...

enter image description here

enter image description here

You can control who can response to this input event using ldap groups for example.

Daniel Majano
  • 976
  • 2
  • 10
  • 18