MCano
MCano

Reputation: 203

Jenkins - Git plugin is not creating local subdirectory for repo when started by CI

I have Jenkins setup using git and use a github hook for continuous integration. I'm using a custom workspace directory. Under source code management, I use Git. I'm only checking out the master branch and I have $GIT_BRANCH-$GIT_COMMIT as my directory location in the "Local subdirectory for repo (optional)" field. In the build section, I'm executing a shell, where I'm performing:

- pwd
- ls
- cd $GIT_BRANCH-$GIT_COMMIT
- ...

The problem I'm getting is when performing, "cd $GIT_BRANCH-$GIT_COMMIT." I receive the following error:

- /tmp/hudson7624299777846840848.sh: 4: cd: can't cd to master-9297429dba145737291168f284796421f73c0ee3 

Per pwd, I'm in the correct directory. ls does not show the directory as being created, which is why I receive this error. After the build has failed, I have checked the build host to see if the clone has been performed and directory has been created. It appears to have not. However, when I execute the build manually, the build passes. ls shows the directory.

Any insight here of why this occurs would be greatly appreciated. My goal here is to create a new directory with the latest source for every build so I can maintain a history of tests, metrics, etc. I'm new to Jenkins, so if there is a better way to do this I'm open to suggestions.

Upvotes: 2

Views: 1433

Answers (2)

jgrump2012
jgrump2012

Reputation: 397

Your variables can be resolved using the following syntax within the custom workspace directory field

${GIT_BRANCH}-${GIT_COMMIT}

Upvotes: 1

jgrump2012
jgrump2012

Reputation: 397

I previously hit a similar problem. My attempts to use a Linux command alias within the 'custom workspace directory' field was not successful.

I'll highlight a secondary option: If archiving is required, you can specify ./recent as the workspace directory and to add a series of post-build commands. For example:

MMMDD=`date +%b%d`
cp -R ./recent ./$MMMDD

Upvotes: 0

Related Questions