Jenkinsfile checkout to a specific folder via git command

1.6k Views Asked by At

I want to run this command in the jenkinsfile

git checkout <repo> <folder name>

but I get this error

[git-checkout-example] Running shell script
+ git checkout [email protected]:sp-digital/jarvis-api.git wahahah
fatal: Not a git repository (or any of the parent directories): .git

Any idea how can I go about doing it in Jenkinsfile? can I checkout the files to a specific folder?

1

There are 1 best solutions below

2
On

can I checkout the files to a specific folder?

You can checkout files of a specific folder, not *to a specific folder.

See git checkout man page

When <paths> is given, git checkout does not switch branches.
It updates the named paths in the working tree from the index file or from a named <tree-ish> (most often a commit).

git checkout with <paths> is used to restore modified or deleted paths to their original contents from the index or replace paths with the contents from a named <tree-ish> (most often a commit-ish).

But in your case, the issue comes from your current working directory when you are executing git checkout xxx -- path: you need to be in a git repo.

Trying to checkout a repo to a path is called git clone, not git checkout.