将文件添加到 CI 管道中的现有分支

发布于 2025-01-14 02:38:28 字数 793 浏览 2 评论 0 原文

我正在编写一个通过 CI 添加文档的脚本。我有一个主存储库,我想将新文档推送到其中,因此需要创建一个新分支并在其中添加这些更改。

  - name: push gitlab documentation
    shell: |
      git init
      git checkout -b newdocs
      git remote add origin https://gitlab-ci-token:{{ gitlab_token }}@{{gitlab.relative_url}}/{{create_repo_response.project.path_with_namespace}}.git
      git config pull.ff only
      git add .
      git commit -m "adding new documentation"
      git push -u origin master

我认为 git push 命令是我遇到问题的地方。

stderr": "切换到新分支 'newdocs'\n错误:src refspec master 不匹配任何\n错误: 无法将一些引用推送到 'sample_git_url.git'", "stderr_lines": ["切换到新分支 'newdocs'", "错误: src refspec master 与任何内容都不匹配", "错误: 未能将一些引用推送到“sample_git_url.git””]

我的最终目标是将我的文档推送到master,但在推送时遇到问题。

I am writing a script that adds docs through the CI. I have a master repo that I want to push new documentation to be pushed to, so would need to create a new branch and add those changes there.

  - name: push gitlab documentation
    shell: |
      git init
      git checkout -b newdocs
      git remote add origin https://gitlab-ci-token:{{ gitlab_token }}@{{gitlab.relative_url}}/{{create_repo_response.project.path_with_namespace}}.git
      git config pull.ff only
      git add .
      git commit -m "adding new documentation"
      git push -u origin master

The git push command is where I believe I am having issues.

stderr": "Switched to a new branch 'newdocs'\nerror: src refspec
master does not match any\nerror: failed to push some refs to
'sample_git_url.git'", "stderr_lines": ["Switched to a new branch
'newdocs'", "error: src refspec master does not match any", "error:
failed to push some refs to 'sample_git_url.git'"]

My end goal is to push my documentation to master, but having issues pushing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪装你 2025-01-21 02:38:28

您可以看到 git clone/git switch 的示例(Git 2.23+,git checkout 否则)/git push

integration_test:
  image: devth/helm:v3.6.3
  stage: integration_test
  script:
    - wget -q https://github.com/mikefarah/yq/releases/download/v4.14.2/yq_linux_amd64.tar.gz -O - | tar xvfz - && chmod +x yq_linux_amd64

    - export CHART_VERSION=$(./yq_linux_amd64 eval .version chart/Chart.yaml)

    - export BRANCH_NAME="auto-update-${SERVICE_NAME}-${CHART_VERSION}"
    - git config --global user.email "[email protected]"
    - git config --global user.name "gitlab"
    - git clone https://${VS_DEPLOYMENT_GIT_REPOSITORY_CREDENTIALS}@gitlab.eox.at/vs/vs-deployment.git
    - cd vs-deployment
    - git switch -c "${BRANCH_NAME}"
    # bump version in Chart.yaml
    - ../yq_linux_amd64 eval "( .dependencies[] | select(.name == \"${SERVICE_NAME}\") | .version ) = \"${CHART_VERSION}\"" --inplace Chart.yaml
    - helm dependency update
    - git add charts/*
    - git commit --all -m "Bump ${SERVICE_NAME} to ${CHART_VERSION}"
    - git push --set-upstream origin "${BRANCH_NAME}"
  only:
    - tags

href="https://gitlab.eox.at/vs/scheduler/-/blob/cb9d0a367d23104068a27152340dc89578889761/.gitlab-ci.yml#L57-78" rel="nofollow noreferrer">此 可以根据您的情况进行调整,并以这种方式推送您的文档。

You can see an example of git clone/git switch (Git 2.23+, git checkout otherwise)/git push in this pipeline script:

integration_test:
  image: devth/helm:v3.6.3
  stage: integration_test
  script:
    - wget -q https://github.com/mikefarah/yq/releases/download/v4.14.2/yq_linux_amd64.tar.gz -O - | tar xvfz - && chmod +x yq_linux_amd64

    - export CHART_VERSION=$(./yq_linux_amd64 eval .version chart/Chart.yaml)

    - export BRANCH_NAME="auto-update-${SERVICE_NAME}-${CHART_VERSION}"
    - git config --global user.email "[email protected]"
    - git config --global user.name "gitlab"
    - git clone https://${VS_DEPLOYMENT_GIT_REPOSITORY_CREDENTIALS}@gitlab.eox.at/vs/vs-deployment.git
    - cd vs-deployment
    - git switch -c "${BRANCH_NAME}"
    # bump version in Chart.yaml
    - ../yq_linux_amd64 eval "( .dependencies[] | select(.name == \"${SERVICE_NAME}\") | .version ) = \"${CHART_VERSION}\"" --inplace Chart.yaml
    - helm dependency update
    - git add charts/*
    - git commit --all -m "Bump ${SERVICE_NAME} to ${CHART_VERSION}"
    - git push --set-upstream origin "${BRANCH_NAME}"
  only:
    - tags

You can adapt it to your case, and push your docs that way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文