我对 CI/CD 概念比较陌生。
我正在尝试使用 Jenkins 中的声明性管道(没有 SCM)克隆 Github 存储库。
如果我在没有任何凭据的情况下执行此操作,那么我可以在控制台输出中看到 Jenkins 已经在尝试克隆该存储库,但需要很长时间。我已经可以看到,在 Jenkins 工作区中,我有一个名为我的 github 存储库的文件夹,但它.git里面只有一个文件夹,它需要永远但永远不会拉出存储库。在互联网上搜索后,我发现缺少访问存储库的权限。
然后我在 Jenkins 中添加了我的 Github 存储库的凭据。我有以下脚本。
pipeline {
agent any
stages {
stage('clone repo') {
steps {
withCredentials(usernamePassword(credentialsId :jenkins-user-github ,passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME' )){
// Get some code from a GitHub repository
bat("""
git config --global credential.username {GIT_USERNAME}
git config --global credential.helper "!echo password={GIT_PASSWORD}; echo"
git clone https://github.com/aakashsehgal/FMU.git
echo "pulled the code"
""")
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Started by user Aakash …Run Code Online (Sandbox Code Playgroud) github jenkins jenkins-plugins jenkins-groovy jenkins-github-plugin