简体   繁体   中英

`mix edeliver build release` push outdated code to build server when running in GitLab CI runner

I am trying to configure my GitLab CI to automatically build my Elixir app and create new release each time when it succeed on master branch. However whenever it comes to deployment it fails due to an old Git repository on build server.

My .gitlab-ci.yml configuration:

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/

And output of edeliver on CI (app builder is 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

Locally when I run mix edeliver build everything works smoothly but I cannot find why when running via CI this fails.

The issue here is how GitLab CI is fetching repositories to test environment. By default it uses git fetch strategy which fetches changes, but do not move branches. There are different solutions to that issue but what I have used is to forcefully set master to current commit by:

git branch -f master HEAD

Before executing mix edeliver . Alternatively you could use git pull to reset to exact branch name instead of master .

I was having this same issue too; I had to use branch= instead of a ref

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM