Estends skipDefaultCheckout to download containerfile too?

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

Hello @ilbonta and welcome to this community. :wave:

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.

Here’s an untested example that may work:

pipeline {
    agent any

    stages {
        stage('Checkout Containerfile') {
            steps {
                    $class: 'GitSCM',
                    branches: [[name: '*/main']],
                    doGenerateSubmoduleConfigurations: false,
                    extensions: [
                        [$class: 'SparseCheckoutPaths', 
                         sparseCheckoutPaths: [[path: 'path/to/Containerfile']]]
                    submoduleCfg: [],
                    userRemoteConfigs: [[url: '']]

        // rest of your pipeline...

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 ‘’ 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. :person_shrugging: