Hey, I am using Jenkins multi-agent setup with both Linux and Windows agents. My version control system is BitBucket. I am currently trying to clone, checkout repos from jenkins scripted pipeline.
Credentials show that git repo is reachable in pipeline configurations. However, I tested from within the Windows agent that it needs manual input to authenticate. A window popups.
How can I overcome this and remove manual input? My current pipeline fails because it does not get reply from that manual input.
To overcome the manual input for authentication when cloning and checking out repositories from a Jenkins pipeline, I guess you could use a credential manager or store the credentials in Jenkins and use them in your pipeline script (if that’s not already the case).
Here is an example of how to configure your Jenkins pipeline to use stored credentials for cloning a BitBucket repository:
1. Store Credentials in Jenkins:
Go to Jenkins Dashboard.
Navigate to Manage Jenkins → Credentials.
Add a new credential with your BitBucket username and password or an SSH key.
2. Use the Credentials in Your Pipeline Script:
pipeline {
agent any
stages {
stage('Clone Repository') {
steps {
script {
// Use the credentials stored in Jenkins
withCredentials([usernamePassword(credentialsId: 'bitbucket-credentials-id', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
// Clone the repository using the stored credentials
if (isUnix()) {
sh 'git clone https://${USERNAME}:${PASSWORD}@bitbucket.org/your-repo/your-project.git'
} else {
bat 'git clone https://${USERNAME}:${PASSWORD}@bitbucket.org/your-repo/your-project.git'
}
}
}
}
}
}
}
You might be trying to use a Windows git client that is configured with a Windows credentials manager. Windows credential managers are designed to be used by a person that is working from a Windows Desktop so that they can respond to the periodic prompts from the credentials manager. Using the same configuration of command line git for a Jenkins agent can lead to authentication prompts from git for Windows.
I use MinGit for Windows on my Windows agents to avoid the risk of credential managers that interfere with command line operations from Jenkins. Instructions are included in the git client plugin documentation.
Yes, I use stored credentials but the pipeline just stucks on that manual input step (I guess). Because there is no error telling about invalid credentials
Hello thank you for an answer. Should this work after installation as per instructions? I had followed the steps to make it an automated installation yet my checkout still stuck on same step.
If your MinGit installation on the agent is the git implementation that is used by the agent, then yes, it should work after installation. If your agent is still using the git for Windows installation with a configured credential manager, then no, it will not change after installation.
When my jobs run on Windows agents, their console output includes lines like:
using credential markewaite-bitbucket-username-password
Cloning the remote Git repository
Avoid fetching tags
Cloning repository https://markewaite@bitbucket.org/markewaite/bin.git
> C:\tools\MinGit-2.47.0.2\mingw64\bin\git.exe init C:\J\OX\workspace\Hosting-Providers\bitbucket\bitbucket-bin-https # timeout=10
Fetching upstream changes from https://markewaite@bitbucket.org/markewaite/bin.git
That output shows me that I am using MinGit 2.47.0.2 to clone from a private Bitbucket repository.
Interesting thing that I put Mingit path higher than old Git install and jenkins still picks older one up. Despite command prompt showing mingit version as default.
Perhaps you know how to work around that?
c:\jenkins-agent\workspace\test winagent and bitbucket>git --version
git version 2.39.2.windows.1
[Pipeline] bat
However, if I use SCM where pipeline configs are in jenkins UI and jenkinsfile in bitbucket, it is stuck on checkout step. Same credentials, same agent.
@MarkEWaite@poddingue it looks like the credentials taken by jenkins from jenkins credentials are fine as I inspect the logs.
The scm steps are properly made - jenkinsfile from bitbucket is taken. However, second time when jenkins checkouts to the same command inside the pipeline, it does not work.
I am using git configuration in jenkins pipeline SCM. Perhaps you see why the first time is working fine (before starting the pipeline) but inside the pipeline it is not good?
it might be related to OS cause controller is starting (which is Linux) but pipeline steps are in windows agent.
However, I tried various git configs, editing many different fields. I still get the same output. Credentials are username and password and are 100% correct as I can use git commands on the same windows agent while specifying them in pipeline itself (not in Pipeline → Definition → SCM → Repositories → Credentials).
Pipeline → Definition → SCM → Repositories → Credentials configuration in UI provides stuck action as I understand due to manual input (I guess)