how to execute a bash script in a jenkins declarative pipeline

70 views
Skip to first unread message

jesus fernandez

unread,
Sep 24, 2020, 9:37:55 AM9/24/20
to Jenkins Users
I have started recently using Jenkins in windows 10. I have a freestyle job that sync from the SCM, build a C++ solution and then it runs a batch script to upload to steam. I am trying to convert it to pipeline as I realized reading the documentation how much more powerful it is. My problem is that on the step to run the .bat file it gets stuck forever, this is the step:
```
...
Stage('batch script'){
            steps{
                bat 'start C:/Users/User/.jenkins/workspace/Project/Steam Build 
                Scripts/scripts/build_dev.bat'
            }
        }
...
```

and this is the simple .bat file:
```
"C:\Users\User\.jenkins\workspace\Project\Steam Build Scripts\builder\steamcmd.exe" +login "someUser" "somePassword" +run_app_build "C:\Users\User\.jenkins\workspace\Project\Steam Build Scripts\scripts\app-build-813780-dev.vdf" +quit

```

running the same file from the freestyle job works fine like this:10IC9 (1).png

Jérôme Godbout

unread,
Sep 24, 2020, 10:07:28 AM9/24/20
to jenkins...@googlegroups.com

Hi,

make sure to escape the path if it has spaces:

bat('start “C:/Users/User/.jenkins/workspace/Project/Steam Build Scripts/scripts/build_dev.bat”');

 

Why do you need the start? Is the command return before completion or something?

running the same file from the freestyle job works fine like this:

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e9a2b099-812c-4cb3-a459-0000f874e455n%40googlegroups.com.

jesus fernandez

unread,
Sep 24, 2020, 10:19:09 AM9/24/20
to Jenkins Users
I also tried with call  but I get this error:
```
16:18:43 C:\Users\User\.jenkins\workspace\pipeline_test>call C:/Users/User/.jenkins/workspace/Age_2_DE/Steam Build Scripts/scripts/build_dev.bat 16:18:43 'C:/Users/User/.jenkins/workspace/Age_2_DE/Steam' is not recognized as an internal or external command, 16:18:43 operable program or batch file.  
```

jesus fernandez

unread,
Sep 24, 2020, 10:26:46 AM9/24/20
to Jenkins Users
but what you suggested worked! probaly I need to improve my batch scripting knowledge as it is none at the moment. THANKS A LOT! 
Reply all
Reply to author
Forward
0 new messages