Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Jenkins job execute shell or Windows command conditionally based on agent OS?

Tags:

I'm trying to build a job that will execute a program on remote agents. The program is either exe when agent is on Windows or shell script when it is on Linux. The program is already deployed on agent machines. I'm looking for a solution that would allow me to conditionally run either exe (Execute Windows batch command) or shell (Execute shell) depending on the agent's OS.

So far I found there is a run condition plugin (https://wiki.jenkins-ci.org/display/JENKINS/Run+Condition+Plugin), whuch would be great, unfortunatelly it does not have check for agent's OS.

Is there any way to accomplish that? Google tells me nothing.

like image 912
Piotr Stachyra Avatar asked Mar 24 '17 15:03

Piotr Stachyra


People also ask

Can Jenkins run shell script?

Using Jenkins built-in "Execute shell" you can run commands using unix shell. If you need to run a job cross platform you cannot use the two standard executors provided by Jenkins. You need a "build step" that can be executed both in Windows and in Unix.

Where do I put Jenkins executable commands?

Jenkins web console > Manage Jenkins > Configure System > Under shell, set the "Shell executable" = C:\cygwin64\bin\sh.exe > Click apply & also click save.


1 Answers

Found something that seems to work:

https://www.techiepie.com/2016/04/14/how-to-identify-jenkins-slave-operating-system-in-a-build/

  • Add Conditional Build Step – Single or Multiple.
  • In Run? Condition select “Execute Shell” and enter command echo "IsShell"
  • Provide Linux Shell Commands as Steps to run if condition is met.
  • Add another Conditional Build Step – Single or Multiple.
  • In Run? Condition Select “Execute Windows Batch Commands” and enter command echo "IsWindows"
  • Provide Windows batch commands as Steps to run if condition is met.
like image 55
Piotr Stachyra Avatar answered Sep 21 '22 11:09

Piotr Stachyra