Multibranch pipeline, problem running scripts

666 views
Skip to first unread message

Adalberto Castelo

unread,
May 30, 2016, 10:52:22 AM5/30/16
to Jenkins Users
Hello!

I'm new to jenkins, and I'm trying to get a simple multibranch pipeline to work. All my Jenkinsfile in my git project does is run a shell script, also in the git project. But all variations I tried end with "java.io.IOException: Cannot run program "./myscript.sh": error=2, No such file or directory".

This is on Jenkins 2.5. Here's a copy of my Jenkinsfile:

node {
  println pwd()
  sh 'ls -lt'
  def command = "./myscript.sh"
  def process = command.execute()
  process.waitFor()
  if (!process.exitValue()) {
    build 'some_other_jenkins_job'
  }
}

myscript.sh is in the same dir as Jenkinsfile.

pwd gives: <jenkins home>/workspace/myproject/master
sh 'ls -lt' gives me nothing (empty dir).

The script and Jenkinsfile can be found at
<jenkins home>/workspace/myproject/master@script, but hardcoding  that as the command path also gives me the same error.

This is a very simple case, so I'm at a loss. I'd would appreciate any insights!

Andrew Bayer

unread,
May 30, 2016, 11:00:52 AM5/30/16
to jenkins...@googlegroups.com
You need to do a "checkout scm" once you're in the node block. Also, try "sh ./myscript.sh" rather than .execute().

A.
--
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/8bab4938-1dc3-497c-87e6-07be63957f74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adalberto Castelo

unread,
May 30, 2016, 12:11:41 PM5/30/16
to Jenkins Users
Thanks, that was a *crucial* piece of information (checkout scm). And yes, sh worked where *.execute didn't, not sure why. I do need to catch the exit status of the script, so now I'm looking into how to do that from sh, but I really want to thank you for the checkout scm tip!

Michael Neale

unread,
May 30, 2016, 7:16:26 PM5/30/16
to Jenkins Users
I forget that "checkout scm" all the time - is there some way to make that more obvious or "fail safe"? (I know you can't just check things out without a node, so it can't be automatic, but it is all to easy to forget now). 

It seems like a "don't checkout scm" may have made more sense. 
Reply all
Reply to author
Forward
0 new messages