【问题标题】:Send files from a branch in one repo to a branch in another repo (repos are not in same account)将文件从一个仓库中的分支发送到另一个仓库中的分支(仓库不在同一个帐户中)
【发布时间】:2023-01-13 18:26:33
【问题描述】:

我需要使用 groovy(jenkins 管道)将发布文件从非产品仓库中的分支发送到产品仓库中的分支。回购不在同一个帐户中。

  • 是否可以将不同帐户中的文件从一个存储库发送到另一个存储库?

我正在使用比特桶。

到目前为止,我已经尝试过,

stage("Create a branhc in remote Repo"){
    steps{
       script{
        withCredentials([[$class: 'usernamePasswordMultiBinding",
                    credentialsId: '####',
                    usernameVariable: '###',
                    passwordVariable: '###',]])

        stdout = sh(script: 'git checkout -b release/1.0.1', returnStdout: true)
        sh(script:'git push origin release/1.0.1 remote repo url')

}}}

当我运行它时,出现以下错误, java.lang.IllegalStateException:必须使用正文调用 withCredentials 步骤

我正在尝试在此处的远程仓库中创建一个新分支。 通过远程回购,我的意思是另一个 git hub 帐户中的回购(在 prod env 中)。

【问题讨论】:

  • 是的是可能的。但是要了解有关如何操作的更多详细信息,您需要改进您的问题并添加更多信息,例如您到目前为止尝试过的内容,示例,向我们展示您的常规代码......
  • 更新了问题。你能检查一下吗?
  • 就 Git 而言,git push 处理提交,不是文件。 (提交然后保存文件:每个提交保存一个每个文件的完整快照.) 因此你必须做出承诺。但是您甚至还没有接触到 Git,因为您的 Jenkins 步骤存在某种问题。

标签: git jenkins groovy bitbucket devops


【解决方案1】:

我找到的解决方案是将分支克隆到一个文件夹并从该文件夹中删除 .git。

sh script: "rm -rf .git"

然后在同一文件夹中初始化一个新的 git,并将其推送到我想要的存储库。

dir("folder"){
    sh script: "git init"
    sh script: "git add *"
    sh script: 'git commit -m "new branch created"'
    sh script: "git checkout -b ${new_branch}"
    withCredentials([[$class: 'UsernamePasswordMultiBinding',
                       credentialsId: 'mycred',
                       usernameVariable: 'username',
                       passwordVariable: 'pass']]){
    sh('git push https://${username}:${pass}@git.example.com:8080/scm/user/reponame ${new_branch})
}

【讨论】:

    猜你喜欢
    • 2016-06-26
    • 2019-03-10
    • 2022-01-14
    • 2022-09-25
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多