Saturday, October 26, 2013

Passing Jenkins Build Variables Using PowerShell's "invoke-command" Cmdlet

Sometimes it is the small things that can take up most of the time when I'm working with PowerShell scripts in Jenkins. I call this the PowerShell Pareto Principle! Usually it is a syntax issue that bites me, but recently I had trouble passing in build variables using the invoke-command cmdlet. This example should clear things up if you encounter the same perplexities which stumped me.

invoke-command your_remote_servername {param(
   [String]$BUILDID,
   [String]$BUILDNUM
   )
   write-host JENKINS-$BUILDID-BUILD$BUILDNUM} -ArgumentList $env:BUILD_ID,$env:BUILD_NUMBER

By using the ArgumentList argument of invoke-command you can pass in outside variables into the Jenkins PowerShell plugin, executing code targeted for a remote server running the WinRM service. That's Hot!™

5 comments:

  1. Thank you for this valuable information. It was really helpful.

    IOSH safety course in Kuwait

    ReplyDelete
  2. very nice articles ....use full information...and thanks for sharing....
    IOSH safety course in Kuwait

    ReplyDelete
  3. You can implement the transfer of variables using the invoke-command cmdlet. This will greatly simplify the selected task for the remote server.

    ReplyDelete
  4. I truly hope that this example should clear all the things up, especially when I encounter the same perplexities which stumped you as well. I'll be further checking out your blog.

    ReplyDelete
  5. I just wanted to add that your own experience with an automation work using Jenkins may help others save their precious time and avoid possible frustrations in learning to use a wonderful automation framework.

    ReplyDelete