sh "git checkout $branch"sh "git add <your file>"sh "git commit -m '...'"sh "git push $url $branch"
棘手的部分是使用我正在使用此方法的相关凭据设置网址-
def getRemoteUrlWithCredentials(credentialsId) { withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: credentialsId, usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) { def scmUrl = scm.getUserRemoteConfigs()[0].getUrl() scmUrl = scmUrl.substring(scmUrl.indexOf("github.com")) return "https://${GIT_USERNAME}:${GIT_PASSWORD}@${scmUrl}" }}其中credentialId是您的git凭据Id。您将需要添加
scm.getUserRemoteConfigs到Manage
Jenkins->处理中脚本批准中的批准列表。
最后一部分-我不确定是否有必要,但也许您需要设置配置user.email和user.name->
def setupConfig(email, userName) { sh "git config user.email $email" sh "git config user.name $userName"}


