Jenkins - Get path to git Repository on slave

1/16/2018

I'm currently running Jenkins on Kubernetes with Helm: After spawning a Jenkins slave and cloning the git Repository, I try to access a folder in this git repository:

def chart_dir = "${WORKSPACE}/flowchart" 

After that I perform a helm lint ${chart_dir}. Unfortunately this does not return a result, since the folder is empty. My guess is, that the workspace path is incorrect.

Does anybody know a way to: 1. List all the files in the Folder on a slave machine 2. Get the proper workspace path on a slave machine?

Greetings J

-- JSt
git
jenkins
kubernetes

1 Answer

1/16/2018

I would need a little more information such as a Jenkinsfile and the script you're executing.

But assuming you're using the git plugin to clone a repo and then execute a script.

The working directory at the time of executing the script is the root of your repository.

The $WORKSPACE environment variable gives you the absolute path to the jenkins workspace (usually /var/lib/jenkins/workspace depending on your setup)

So executing:

helm lint ./flowchart

Should work just fine.

You can find more information about the exposed environment variables here: https://wiki.jenkins.io/display/JENKINS/Building+a+software+project https://wiki.jenkins.io/display/JENKINS/Git+Plugin

-- Esteban Garcia
Source: StackOverflow