我想更改文件并在 gitlab-ci 管道内提交更改
我尝试在脚本中编写普通的 git 命令
script:
- git clone [email protected] /cdn-cgi/l/email-protection
- cd project file
- touch test.txt
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git add .
- git commit -m "testing autocommit"
- git push
我找不到命令 git 或类似的东西,我知道它与标签有关,但如果我尝试添加 git 标签,它会说没有活动的运行程序。有人知道如何在 gitlab-ci 上运行 git 命令吗?
首先你需要确保你可以实际使用git
,所以要么在shell
执行器位于具有git
或使用docker
执行器并使用具有git
安装。
您将遇到的下一个问题是您无法推送到 Git(lab),因为您无法输入凭据。
所以解决方案是创建一个 ssh 密钥对并通过以下方式将 ssh 私钥加载到您的 CI 环境中CI/CD 变量 https://docs.gitlab.com/ee/ci/variables/,也给你添加对应的公钥你的 Gitlab) 帐户 https://docs.gitlab.com/ee/ssh/.
Source: https://about.gitlab.com/2017/11/02/automating-boring-git-operations-gitlab-ci/ https://about.gitlab.com/2017/11/02/automating-boring-git-operations-gitlab-ci/
Your .gitlab-ci.yml
然后看起来像这样:
job-name:
stage: touch
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$GIT_SSH_PRIV_KEY")
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- mkdir -p ~/.ssh
- cat gitlab-known-hosts >> ~/.ssh/known_hosts
script:
- git clone [email protected] /cdn-cgi/l/email-protection
- cd project file
- touch test.txt
- git add .
- git commit -m "testing autocommit"
- git push
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)