[OSX] How to invoke Terminal.app in a Freestyle job?

I am new to Jenkins on OSX machines after previously working on Windows. To invoke CMD, I would simply select ‘Execute Windows batch command’ under ‘Build steps’ in a Freestyle project to run a .bat script. However, you can’t run batch scripts on OSX machines (unless I’m missing something) – is there a way that Terminal.app can be invoked in a Jenkins Freestyle project? Or is there a way to execute a batch script in a Jenkins Freestyle project using OSX?

System specs:

  • Jenkins LTS controller 2.361.2.
  • macOS Monterey 12.6.
  • Safari browser.

Any assistance in this matter is greatly appreciated!

The default shell on macOS is zsh, when you do “Execute Shell” it will launch the default shell and run the commands you specify in the build step. You will have to change the syntax to be zsh syntax (there may be other shells available on the system too).

You can use a shebang in the script to force a specific shell.
#!/bin/bash

Hey @slide_o_mix and thank you for the response!

Can you show me an example? Sorry quite new to all this!

Hi @mawinter69 and thank you for the response!

Can you show me an example of how one can do this? Very new to macOS!

Instead of selecting “Execute Batch Script” for the build step, select “Execute Shell”. Then you can enter shell commands in the text box just like you had for “Execute Batch Script”. You’ll have to port your batch commands to shell script commands (by default zsh on macOS but you can put a shebang Shebang (Unix) - Wikipedia as the first line - it MUST be the first line - to change to a different shell).

2 Likes

Appreciate the support @slide_o_mix, thank you!

Appreciate the assistance @mawinter69, thank you!