Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Jenkinsfile中使用Git令牌_Git_Jenkins_Jenkins Pipeline - Fatal编程技术网

如何在Jenkinsfile中使用Git令牌

如何在Jenkinsfile中使用Git令牌,git,jenkins,jenkins-pipeline,Git,Jenkins,Jenkins Pipeline,我正在尝试使用Jenkinsfile克隆git分支并合并它们。 框架代码如下: pipeline { agent { label "" } stages { stage("Git") { steps { git( url: , credentialsId: ) } } } } 每次我运行这个,我都会得到错误 stderr:remote

我正在尝试使用Jenkinsfile克隆git分支并合并它们。 框架代码如下:

pipeline {
    agent { 
        label ""
    }
    stages {
        stage("Git") {
            steps {
                git( url: , credentialsId: )
            }
        }
    }
}
每次我运行这个,我都会得到错误

stderr:remote:Git操作不提供密码身份验证。 远程:必须使用个人访问令牌或SSH密钥


有人知道如何在jenkinsfile中使用git令牌吗?我非常感谢任何帮助。谢谢

使用GitHub访问令牌时,您必须使用标准用户名和密码凭据,其中用户名与GitHub用户名相同,密码是您的访问令牌

来源-


创建个人访问令牌的步骤-

您应该配置
个人访问令牌
SSH密钥
。SSH密钥的示例:

然后转到Jenkins>凭证>添加新凭证。它是一种带有私钥的SSH用户名,内容是您的SSH私钥。请注意所创建凭据的ID

现在,您可以在上面的代码中填入
凭证ID:

这对我很有用:

  withCredentials([string(credentialsId: "GITHUB_TOKEN", variable: 'GITHUB_TOKEN')]) {
    // An example for getting the statuses for a commit using GITHUB_TOKEN:
    // Use env.GITHUB_TOKEN here or just let shell expand it...
    def statusJson = sh returnStdout: true, 
         script: "curl --fail -s -X GET -H 'Accept: application/vnd.github.v3+json' -u " +
          ":\$GITHUB_TOKEN " +
 "https://api.github.com/repos/myowner/myrepo/commits/$gitCommit/statuses"    

  }