linuxjenkinsgroovy

Jenkins - No such file or directory after moving to Linux


I get the following error when running the following groovy code since moving jenkins node to linux:

java.io.FileNotFoundException: /home/jenkins/agent/workspace/tompia_system/.conf/config.json (No such file or directory)

function:

import groovy.json.JsonSlurperClassic
def call() {
    def inputFile = new File("${WORKSPACE}/.conf/config.json")
    def InputJSON = new JsonSlurperClassic().parseText(inputFile.text)
    def branch = env.BRANCH_NAME
    return InputJSON << InputJSON.targets."$branch";
}

Path is correct. Worked fine on the windows node. The part that crashes is the parsing with jsonslurper.


Solution

  • Thanks for the suggestions.

    Before moving to openshift the agent was the same Windows Server as the Jenkins master. This seems to be the reason why the "new File()" part worked there, because it references the master system for some reason.

    As daggett suggests the part should look like this:

    def props = readJSON file: '.conf/config.json'
    

    The Pipeline Utility Steps Plugin is required for this step.