在 GitLab CI runner 中 运行 时,`mix edeliver build release` 将过时的代码推送到构建服务器
`mix edeliver build release` push outdated code to build server when running in GitLab CI runner
我正在尝试配置我的 GitLab CI 以自动构建我的 Elixir 应用程序并在每次在 master
分支上成功时创建新版本。然而,每当涉及部署时,由于构建服务器上的旧 Git 存储库而失败。
我的.gitlab-ci.yml
配置:
image: 'elixir:1.3.3'
services:
- postgres
# …
staging:
stage: deploy
environment: staging
tags:
- elixir
before_script:
- mix local.hex --force
- mix do deps.get, compile
- 'which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)'
- eval $(ssh-agent -s)
- echo "$SSH_DEPLOY_STAGING_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
script:
- mix edeliver build release --revision=$CI_BUILD_REF --auto-version=git-revision
- mix edeliver deploy to staging
only:
- master
cache:
paths:
- _build/
- deps/
edeliver
在 CI 上的输出(应用程序构建器是 Distillery):
$ which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 373
$ echo "$SSH_DEPLOY_STAGING_KEY" | tr -d '\r' | ssh-add -
Identity added: (stdin) (hauleth@niuniobook)
$ mkdir -p ~/.ssh
$ mix edeliver build release --revision=$CI_BUILD_REF --auto-version=git-revision
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
BUILDING RELEASE OF ONEMEDICAL APP ON BUILD HOST
-----> Authorizing hosts
-----> Ensuring hosts are ready to accept git pushes
-----> Pushing new commits with git to: app@build.server
-----> Resetting remote hosts to 3faf1d077f95ce7207cac7d14dd25b33d648d710
fatal: Could not parse object '3faf1d077f95ce7207cac7d14dd25b33d648d710'.
A remote command failed on:
app@build.server
Output of the command is shown above and the command executed
on that host is printed below for debugging purposes:
FAILED with exit status 128:
set -e
cd /tmp/edeliver/app/builds
git reset --hard 3faf1d077f95ce7207cac7d14dd25b33d648d710
ERROR: Build failed: exit code 1
在本地,当我 运行 mix edeliver build
一切正常时,我无法找到为什么当 运行ning 通过 CI 时失败。
我也遇到了同样的问题;我不得不使用 branch=
而不是 ref
这里的问题是 GitLab CI 如何将存储库提取到测试环境。默认情况下,它使用 git fetch
策略获取更改,但不移动分支。该问题有不同的解决方案,但我使用的是通过以下方式强制将 master
设置为当前提交:
git branch -f master HEAD
执行前mix edeliver
。或者,您可以使用 git pull
重置为确切的分支名称,而不是 master
.
我正在尝试配置我的 GitLab CI 以自动构建我的 Elixir 应用程序并在每次在 master
分支上成功时创建新版本。然而,每当涉及部署时,由于构建服务器上的旧 Git 存储库而失败。
我的.gitlab-ci.yml
配置:
image: 'elixir:1.3.3'
services:
- postgres
# …
staging:
stage: deploy
environment: staging
tags:
- elixir
before_script:
- mix local.hex --force
- mix do deps.get, compile
- 'which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)'
- eval $(ssh-agent -s)
- echo "$SSH_DEPLOY_STAGING_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
script:
- mix edeliver build release --revision=$CI_BUILD_REF --auto-version=git-revision
- mix edeliver deploy to staging
only:
- master
cache:
paths:
- _build/
- deps/
edeliver
在 CI 上的输出(应用程序构建器是 Distillery):
$ which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 373
$ echo "$SSH_DEPLOY_STAGING_KEY" | tr -d '\r' | ssh-add -
Identity added: (stdin) (hauleth@niuniobook)
$ mkdir -p ~/.ssh
$ mix edeliver build release --revision=$CI_BUILD_REF --auto-version=git-revision
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
tput: No value for $TERM and no -T specified
BUILDING RELEASE OF ONEMEDICAL APP ON BUILD HOST
-----> Authorizing hosts
-----> Ensuring hosts are ready to accept git pushes
-----> Pushing new commits with git to: app@build.server
-----> Resetting remote hosts to 3faf1d077f95ce7207cac7d14dd25b33d648d710
fatal: Could not parse object '3faf1d077f95ce7207cac7d14dd25b33d648d710'.
A remote command failed on:
app@build.server
Output of the command is shown above and the command executed
on that host is printed below for debugging purposes:
FAILED with exit status 128:
set -e
cd /tmp/edeliver/app/builds
git reset --hard 3faf1d077f95ce7207cac7d14dd25b33d648d710
ERROR: Build failed: exit code 1
在本地,当我 运行 mix edeliver build
一切正常时,我无法找到为什么当 运行ning 通过 CI 时失败。
我也遇到了同样的问题;我不得不使用 branch=
而不是 ref
这里的问题是 GitLab CI 如何将存储库提取到测试环境。默认情况下,它使用 git fetch
策略获取更改,但不移动分支。该问题有不同的解决方案,但我使用的是通过以下方式强制将 master
设置为当前提交:
git branch -f master HEAD
执行前mix edeliver
。或者,您可以使用 git pull
重置为确切的分支名称,而不是 master
.