[JIRA] [powershell-plugin] (JENKINS-34581) Please add support for Pipelines to the Powershell plugin

6 views
Skip to first unread message

stuart@somepointinthefuture.co.nz (JIRA)

unread,
May 3, 2016, 6:05:02 PM5/3/16
to jenkinsc...@googlegroups.com
Stuart Whelan created an issue
 
Jenkins / Improvement JENKINS-34581
Please add support for Pipelines to the Powershell plugin
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: powershell-plugin
Created: 2016/May/03 10:04 PM
Labels: pipeline powershell windows microsoft
Priority: Major Major
Reporter: Stuart Whelan

I would like to use the powershell plugin from within pipelines, please add support for the pipelines to the powershell plugin.

This is especially important as we approach Jenkins 2.0 and its move towards pipelines.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.2#64017-sha1:e244265)
Atlassian logo

pwolf@cloudbees.com (JIRA)

unread,
May 5, 2016, 6:02:01 PM5/5/16
to jenkinsc...@googlegroups.com
Patrick Wolf updated an issue
Change By: Patrick Wolf
Labels: microsoft pipeline powershell windows  workflow

andrew.bayer@gmail.com (JIRA)

unread,
May 5, 2016, 6:07:01 PM5/5/16
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Improvement JENKINS-34581
 
Re: Please add support for Pipelines to the Powershell plugin

It'd be really great to get real Pipeline integration, a la sh and bat - i.e., a DurableTaskStep implementation for Powershell.

jglick@cloudbees.com (JIRA)

unread,
May 9, 2016, 10:47:01 AM5/9/16
to jenkinsc...@googlegroups.com

For now you should use the bat step with powershell.exe. Making Powershell be a SimpleBuildStep is a bad idea.

jnord@cloudbees.com (JIRA)

unread,
Jul 22, 2016, 6:20:02 AM7/22/16
to jenkinsc...@googlegroups.com
James Nord updated an issue
 
Change By: James Nord
Component/s: durable-task-plugin
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

cchapman@kinaxis.com (JIRA)

unread,
Sep 1, 2016, 8:53:02 PM9/1/16
to jenkinsc...@googlegroups.com

jglick@cloudbees.com (JIRA)

unread,
Oct 4, 2016, 11:44:01 AM10/4/16
to jenkinsc...@googlegroups.com

Because it would not be durable.

The choices are:

  • use JENKINS-37011 to provide something that looks for purposes of Snippet Generator and script syntax like a regular step, but which really just calls bat with some wrapper code
  • implement a first-class FileMonitoringTask that bypasses *.bat entirely

jglick@cloudbees.com (JIRA)

unread,
Oct 7, 2016, 4:52:01 PM10/7/16
to jenkinsc...@googlegroups.com

I would vote for the second choice. Probably more robust. Might be easier to implement something like JENKINS-25053 in that mode too.

akorczynski@kcura.com (JIRA)

unread,
Nov 23, 2016, 1:19:13 PM11/23/16
to jenkinsc...@googlegroups.com

Jesse Glick in the meantime, do you know a there a better way of handling powershell inside bat step ? so that when powershell script fails (for example it run some tests and they fail), the bat fails too and the build/pipeline fails ? Right now jenkins thinks the bat step went succesfully and we need to some tricks along the lines of http://jenkins-ci.361315.n4.nabble.com/Fail-the-build-if-the-Powershell-script-fails-td2164982.html

I also vote for native PS support inside pipelines.

akorczynski@kcura.com (JIRA)

unread,
Nov 23, 2016, 1:20:09 PM11/23/16
to jenkinsc...@googlegroups.com
Severian Autarch edited a comment on Improvement JENKINS-34581
[~jglick] in the meantime, do you know a there a better way of handling powershell inside bat step ? so that when powershell script fails (for example it run some tests and they fail), the bat fails too and the build/pipeline fails ? Right now jenkins thinks the bat step went succesfully successfully and we need to some tricks along the lines of http://jenkins-ci.361315.n4.nabble.com/Fail-the-build-if-the-Powershell-script-fails-td2164982.html


I also vote for native PS support inside pipelines.

akorczynski@kcura.com (JIRA)

unread,
Nov 23, 2016, 1:20:17 PM11/23/16
to jenkinsc...@googlegroups.com
Severian Autarch edited a comment on Improvement JENKINS-34581
[~jglick] in the meantime, do you know a there a better way of handling powershell inside bat step ? so that when powershell script fails (for example it run some tests and they fail), the bat fails too and the build/pipeline fails ? Right now jenkins thinks the bat step went successfully and we need to do some tricks along the lines of http://jenkins-ci.361315.n4.nabble.com/Fail-the-build-if-the-Powershell-script-fails-td2164982.html


I also vote for native PS support inside pipelines.

jglick@cloudbees.com (JIRA)

unread,
Nov 30, 2016, 6:23:04 PM11/30/16
to jenkinsc...@googlegroups.com

I am the last person to ask for advice on Windows shell scripting matters. Try variants outside Jenkins until you find something that works.

jreed@glynlyon.com (JIRA)

unread,
Nov 30, 2016, 7:52:07 PM11/30/16
to jenkinsc...@googlegroups.com

I'm eagerly following this issue as PowerShell is big part of our Jenkins use. The "implement a first-class FileMonitoringTask that bypasses *.bat entirely" mentioned above by Jesse is something I am eager and interested in evaluating/experiencing/testing. However as we are currently limited to Windows traditional command execution (and its binary feedback) via the bat mechanism I can speak to gotchas as it pertains to powershell.exe and success/failure behaviors. Both for Andrzej's concern above and others who may wind their way here. I've been using the bat step for a little while now and the traditional freestyle PowerShell plugin for some time.

The biggest thing to keep in mind are PowerShell's idea of a terminating errors and non-terminating errors. Without extra effort PowerShell non-terminating errors are not going to cause Jenkins nor the Windows command execution that marries the two to be recognized as a "failure". Understanding your code and making sure that you generate terminating errors where needed to get that "failure" surfaced in Jenkins is critical. Additionally knowing when and how the PowerShell.exe interpreter registers the failure or success of native exe's vs cmdlets.

Check the following URLs for clarity on that. Bottom line the "-ErrorAction Stop" builtin parameter to cmdlets is your friend here, along with try/catch/finally. And also making sure you understand "$LastExitCode vs $?", the builtin PowerShell variables and how you exit your script in the context of Jenkins.

https://blogs.technet.microsoft.com/heyscriptingguy/2015/09/16/understanding-non-terminating-errors-in-powershell/
http://stackoverflow.com/questions/10666035/difference-between-and-lastexitcode-in-powershell

ssutherland@ea.com (JIRA)

unread,
Dec 2, 2016, 8:51:03 PM12/2/16
to jenkinsc...@googlegroups.com

ssutherland@ea.com (JIRA)

unread,
Dec 2, 2016, 8:51:04 PM12/2/16
to jenkinsc...@googlegroups.com
Sean Sutherland assigned an issue to Unassigned

kbrowder@gmail.com (JIRA)

unread,
Jan 5, 2017, 3:58:02 PM1/5/17
to jenkinsc...@googlegroups.com
Kevin Browder commented on Improvement JENKINS-34581
 
Re: Please add support for Pipelines to the Powershell plugin

It does seem useful to have first class support for this given how limiting bat can be, however I think the following works in the normal "bat" step in the meantime:

bat '''
<# : BATCH
@echo off & setlocal
powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
exit /b %errorlevel%
: END BATCH #>
Write-Output "Hello World"
exit 2
'''

Super ugly but functional.
Stolen from http://stackoverflow.com/a/33065387/2242609

jreed@glynlyon.com (JIRA)

unread,
Jan 5, 2017, 5:18:02 PM1/5/17
to jenkinsc...@googlegroups.com

That is an interesting approach. What I've settled on is the following simple basic Jenkinfile example:

node {
    checkout scm

    stage ('Build Module'){
        bat "powershell.exe -NonInteractive -ExecutionPolicy Bypass -Command \"& '.\\01_build.ps1'\""
    }
   stage ('Test Module'){
        bat "powershell.exe -NonInteractive -ExecutionPolicy Bypass -Command \"& '.\\02_test.ps1'\""
    }
   stage ('Deploy Module'){
        bat "powershell.exe -NonInteractive -ExecutionPolicy Bypass -Command \"& '.\\03_deploy.ps1'\""
    }
}

There's a lot of escaping going on but I think it most closely resembles what the PowerShell freestyle plugin is doing and how it is executing the script code. It also keeps the "code" out of my Jenkinsfile, which I prefer to be more static. If my various .ps1 files are properly handling terminating and non-terminating errors appropriately then I'm getting the results I expect to see in my various stages. Jenkins then reflects that via build results or Blue Ocean or what not. I have this successfully working and supporting a number of traditional CI/CD PowerShell module build/test/deploy pipelines and a number of other more unique non-traditional pipelines that are doing more workflow and less CI/CD style things. Bottom line if my scripts fail they show fail and when they work the pipeline keeps going.

testautomater1@gmail.com (JIRA)

unread,
Feb 3, 2017, 10:22:02 AM2/3/17
to jenkinsc...@googlegroups.com

Indeed you need to use lot of escaping (see example below) to execute simple statements. Adding PowerShell support without use of bat as workaround could save lot of time and efforts.

bat "powershell Copy-Item -path ${mypath}\\Deployment\\Debug\\Server -Destination \\\\myserver\\d\$\\SQLServer -Force -Recurse"

jglick@cloudbees.com (JIRA)

unread,
Feb 15, 2017, 2:27:12 PM2/15/17
to jenkinsc...@googlegroups.com

Kevin Browder as an interim workaround, you could create a repo on github.com with vars/powershell.groovy so that people could

@Library('github.com/kbrowser/powershell') import _
powershell '''
Write-Output "Hello World"
exit 2
'''

marley.kudiabor@cubic.com (JIRA)

unread,
Feb 28, 2017, 1:58:02 PM2/28/17
to jenkinsc...@googlegroups.com

Jesse Glick What are the contents of vars/powershell.groovy? Where can I find that library?

jglick@cloudbees.com (JIRA)

unread,
Feb 28, 2017, 2:21:06 PM2/28/17
to jenkinsc...@googlegroups.com

It does not exist, I was suggesting one be created.

vijayt.124@gmail.com (JIRA)

unread,
Mar 2, 2017, 2:43:01 AM3/2/17
to jenkinsc...@googlegroups.com

Do we have plan to support powershell in Jenkins pipeline in upcoming releases, or we need to rely on bat as suggested in this thread

jglick@cloudbees.com (JIRA)

unread,
Mar 3, 2017, 5:30:05 PM3/3/17
to jenkinsc...@googlegroups.com

gabrielloewen@outlook.com (JIRA)

unread,
Mar 6, 2017, 8:50:06 PM3/6/17
to jenkinsc...@googlegroups.com

I have added powershell support to the durable task plugin, and I am currently testing it. I will respond to this thread once I am ready to submit a PR.

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

gabrielloewen@outlook.com (JIRA)

unread,
Mar 7, 2017, 3:12:02 PM3/7/17
to jenkinsc...@googlegroups.com

gabrielloewen@outlook.com (JIRA)

unread,
Mar 7, 2017, 3:13:04 PM3/7/17
to jenkinsc...@googlegroups.com
Gabriel Loewen started work on Improvement JENKINS-34581
 
Change By: Gabriel Loewen
Status: Open In Progress

gabloe@microsoft.com (JIRA)

unread,
Mar 9, 2017, 5:38:12 PM3/9/17
to jenkinsc...@googlegroups.com
Gabriel Loewen updated an issue
Change By: Gabriel Loewen
Attachment: input.png
Attachment: result.PNG

gabloe@microsoft.com (JIRA)

unread,
Mar 9, 2017, 5:38:12 PM3/9/17
to jenkinsc...@googlegroups.com
 
Re: Please add support for Pipelines to the Powershell plugin

My changes are in the following repositories:

https://github.com/gabloe/durable-task-plugin

https://github.com/gabloe/workflow-durable-task-step-plugin

All unit tests are passing during build, and I've tested it in Jenkins using some example pipeline code (See attached screenshots).

 

marley.kudiabor@cubic.com (JIRA)

unread,
Mar 13, 2017, 10:30:09 AM3/13/17
to jenkinsc...@googlegroups.com

Gabriel Loewen Will these changes be rolled into the next version or will we need to pull your change and build it ourselves?

testautomater1@gmail.com (JIRA)

unread,
Mar 15, 2017, 6:30:03 AM3/15/17
to jenkinsc...@googlegroups.com

Thanks Gabriel Loewen for the support. Hoping powershell support will be available in Jenkins pipeline soon.

gabloe@microsoft.com (JIRA)

unread,
Mar 19, 2017, 5:09:15 PM3/19/17
to jenkinsc...@googlegroups.com

@Marley Kudiabor - Please don't build out of my repo as the plugin may have changes made during the review process. This needs to be fully vetted and accepted into the maintained repository. So you should wait for the official support.

I have submitted 2 pull requests for review:
https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/35
https://github.com/jenkinsci/durable-task-plugin/pull/39

Thanks,
Gabriel

gabloe@microsoft.com (JIRA)

unread,
Mar 19, 2017, 5:09:21 PM3/19/17
to jenkinsc...@googlegroups.com

gabloe@microsoft.com (JIRA)

unread,
Mar 19, 2017, 5:09:22 PM3/19/17
to jenkinsc...@googlegroups.com

michaeldkfowler@gmail.com (JIRA)

unread,
Mar 7, 2018, 1:54:03 AM3/7/18
to jenkinsc...@googlegroups.com

sebastianslutzky@gmail.com (JIRA)

unread,
Oct 21, 2019, 11:05:03 AM10/21/19
to jenkinsc...@googlegroups.com
sebastian slutzky commented on Improvement JENKINS-34581
 
Re: Please add support for Pipelines to the Powershell plugin

Gabriel Loewen Running powershell in the Jenkins Pipeline is hardcoded to use no profile. The powershell plugin defaults to the opposite. Can this be made configurable?

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages