My pipeline use a Jenkinsfile and need Containerfile to generate an image.
skipDefaultCheckout option is really usefull to avoid to checkout the repo, because use the SCM job config to connect to the repo, system credential and host key verification configuration, …but I need to download Containerfile too. What is the better solution to resolve the topic?
Using sh “git archive…” I have to define again all the ssh config
Using sshagent plugin i have to add a ssh config clone
Using withCredentials wrapper I receive an “Host key verification failed.” error
I think you could use the checkout step in your Jenkinsfile to selectively checkout only the Containerfile from your repository. This should allow you to avoid checking out the entire repository, while still being able to access the Containerfile.
In this example, replace ‘*/main’ with the branch you want to checkout, ‘path/to/Containerfile’ with the path to your Containerfile in the repository, and ‘git@github.com:username/repo.git’ with the URL of your Git repository.
The SparseCheckoutPaths extension is used to specify the paths that should be checked out. In this case, only the Containerfile is checked out.
This approach uses the Git SCM plugin, which should handle the SSH configuration based on the settings in your Jenkins system configuration.
At least, I hope it does.