3

I have a Jenkinfile that looks like:

node {

def rootDir = pwd()

def externalMethod = load("${rootDir}/ci/jenkins/shops.groovy")

// Call the method we defined in externalMethod.
externalMethod.lookAtThis("Simon")

}

And another file at ci/jenkins/shops.groovy

def lookAtThis(String whoAreYou) {
    echo "Look at this, ${whoAreYou}! You loaded this from another file!"
}

But Jenkins is returning the error

java.io.IOException: java.io.FileNotFoundException: /root/workspace/lush-global-soa-architecture/develop/ci/jenkins/shops.groovy (No such file or directory)

I'm not sure why it can't find this file.

Simon I
  • 3,406
  • 4
  • 26
  • 32
  • 1
    Perhaps it's a unix permission issue. Does the user running the script have read access to *shops.groovy*? – Luciano van der Veekens Jan 25 '17 at 10:56
  • I have also tried def externalMethod = load("${rootDir}@script/ci/jenkins/shops.groovy") – Simon I Jan 25 '17 at 10:56
  • @luc14n0 I'm not sure, the worker pulls the files down from Github. I could try setting the file permissions and pushing up. – Simon I Jan 25 '17 at 10:59
  • Yeah definitely give that a try. I've had issues similar to this before. – Luciano van der Veekens Jan 25 '17 at 11:02
  • No luck @luc14n0, I've changed file permission and am still getting 'file not found' – Simon I Jan 25 '17 at 11:21
  • Simon, can you expand your question by providing the output of `ls -l /root/workspace/lush-global-soa-architecture/develop/ci/jenkins/shops.groovy` and process information about the running jenkins instance. – Luciano van der Veekens Jan 25 '17 at 12:35
  • @Simon Iook at this example http://stackoverflow.com/a/38108449/6528221 – Anton Shishkin Jan 25 '17 at 13:00
  • @luc14n0 `ls -l /root/workspace/lush-global-soa-architecture/develop/ci/jenk‌​ins/shops.groovy` gave back `ls: cannot access /root/workspace/lush-global-soa-architecture/develop/ci/jenk‌​ins/shops.groovy: No such file or directory` I also tried `ls -l /root/workspace/lush-global-soa-architecture/develop` and it gave back `total 0` – Simon I Jan 25 '17 at 13:58
  • @anton That question is what got me started, but I don't seem to be able to get it working. – Simon I Jan 25 '17 at 14:01
  • @Simon because your path in "load" function is wrong. You need to use path "${rootDir}@script/ci/jenkins/shops.groovy" – Anton Shishkin Jan 26 '17 at 07:00

1 Answers1

2

I got it working, turns out I needed to checkout scm before I could load the file.

checkout scm
Simon I
  • 3,406
  • 4
  • 26
  • 32