gitjenkinscmakecmake-modules

Jenkins - Pass Git credential during CMake FetchContent


Context

I'm currently working on a CMake project that uses Jenkins for its continuous integration.

This CMake project includes a number of libraries which it retrieves using FetchContent. Basically, rather than using Git submodules, we chose to use FetchContent.

The Jenkins that clone the project, and credentials to this project are easily passed on thanks to the git plugin.

Problem

The problem is that the git plugin does not pass credentials as it did during the clone, in the configuration phase of my CMake project, so that the configuration fails. I have this logs

[1/9] Performing download step (git clone) for '<my_module>-populate'

Cloning into '<my_module>'...
fatal: could not read Username for 'https://<my_private_server>': No such device or address

The start of a solution?

After much searching, I came to use the withCredentials function, which makes my stage look like this:

stage('Project Configure') {
    steps {
        withCredentials([gitUsernamePassword(credentialsId: '<CredentialID>']) {
            sh "cmake --preset=MyPreset"
        }
    }
}

But this doesn't completely solve the problem, as only the user name is passed, but not the password. The logs are:

[1/9] Performing download step (git clone) for '<my_module>-populate'
Cloning into '<my_module>'...
****: 3: ?!: not found
error: unable to read askpass response from ****
fatal: could not read Password for 'https://<my_user>@<my_private_server>': terminal prompts disabled

Limitation

I also thought of using the SSH link instead of the HTTPS link in the Git repository, but that doesn't work, because the functionality isn't available on the server.


Solution

  • Finally, after much searching, I found the solution (or rather the error).

    All you have to do is this:

    stage('Project Configure') {
        steps {
             withCredentials([gitUsernamePassword(credentialsId: '<CredentialID>']) {
                sh "cmake --preset=MyPreset"
            }
        }
    }
    

    The error I had was that my password contained special characters (notably a &) and that they were interpreted (linked to this issue?).

    I just had to change the password for it to work properly.