I am trying to figure out a way to get the remote git project name in a jenkins job as a env variable. I would like to use the project name as the "local subdirectory name" when jenkins clones the repo. is there a way to do this?
maybe something like ${GIT_REPO_NAME}
I know that there is ${GIT_REPO_URL}
and it includes the project name, but I need to be able to use this in the local sub directory field.
if someone has a better solution for this I am all ears.
thank you!
Step 1: go to your GitHub repository and click on 'Settings'. Step 2: Click on Webhooks and then click on 'Add webhook'. Step 3: In the 'Payload URL' field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/.
Access local git repository in Jenkins docker container To mount your local git repository folder to a Jenkins container run the container with an additional -v or --volume flag. The basic docker run statement from the official docker image documentation would then look like. The :ro option is optional.
If you want to be able to dynamically give a Git branch to use in a Jenkins build then you'll need to do a couple of things. Then, in your Pipeline configuration, under Branches to build, add your parameter name inside the Branch Specifier box, surrounded by ${} . Jenkins will expand your variable when the job runs.
Here's a simple one-liner:
env.GIT_REPO_NAME = env.GIT_URL.replaceFirst(/^.*\/([^\/]+?).git$/, '$1')
/^.*\/([^\/]+?).git$/
is a regex that creates a back-reference to just the repo name.
^.*?(?::\/\/.*?\/|:)(.*).git$
use this pattern for both http and ssh if you want to get full repo path {owner}/{repo_name}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With