Is it possible to run a command defined in pipeline in a separate terminal / console?

Hi guys,

I am running Jenkins in an OSX EC2 instance and everything is working fine. I have one particular requirement which I am currently working for quite sometime. Let me explain the scenario in simple words. I have a pipeline script like below;

pipeline {
    agent {
        label 'master'
    tools {
        nodejs "node-v14.17.5"
    stages {
        stage('stage1') {
            steps {
                    sh 'command_a'
                    sh 'command_b'
        stage('stage2') {
            steps {
                    sh 'command_c'

This might looks fine, but I have one requirement. command_a in stage_1 should be running all the time, because command _b and command_c are depending on that. Basically command_a is yarn start which is required for IOS app build. Now, I can very well proceed with the pipeline by replacing command_a with something like nohup command_a >> command_a.log & . But when I try this command locally, the server (the command actually starts metro server) starts, but it will get stuck in the middle. I figured out that the server need to run in foreground, which will not return the control back to console.

In real world, without Jenkins, the process works like this;

  1. I open up a terminal and execute command_a in it. The process will run in foreground.
  2. I open up a another terminal and run command_b and command_c in it, which works well.

Then I thought of writing a script, which automatically launch another terminal from existing terminal and execute the required command in it. I ended up creating a script like this;

osascript -e 'tell app "Terminal" to do script "cd /workspace/MyPipeline/dir_a && command_a"'

This worked well in the mac terminal. It will execute the command in a separate terminal after going to the specified directory. The equivalent jenkins script I included in the pipeline is like below;

sh 'osascript -e \'tell app "Terminal" to do script "cd /workspace/MyPipeline/dir_a && command_a"\''

But it returned an error like below;

execution error: An error of type -10826 has occurred. (-10826)

So, my question is, is there any possibility to achieve executing one command while running another command in foreground using Jenkins pipeline? Basically, two parallel executions.

Thanks in advance.

Though you will probably need some way to stop your first process, once command_b and command_c are finished

1 Like