CircleCI分支构建失败,但标记构建成功

时间:2018-08-20 21:17:05

标签: circleci circleci-2.0 circleci-workflows

我正在CircleCI上构建我的项目,并且我有一个看起来像这样的构建工作:

  build:
    <<: *defaults
  steps:
    - checkout
    - setup_remote_docker
    - run:
        name: Install pip
        command: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py
    - run:
        name: Install AWS CLI
        command: curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" && unzip awscli-bundle.zip && sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
    - run:
        name: Login to Docker Registry
        command: aws ecr get-login --no-include-email --region us-east-1 | sh
    - run:
        name: Install Dep
        command: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
    - run:
        name: Save Version Number
        command: echo "export VERSION_NUM=${CIRCLE_TAG}.${CIRCLE_BUILD_NUM}" > deployment/dev/.env
    - run:
        name: Build App
        command: source deployment/dev/.env && docker-compose -f deployment/dev/docker-compose.yml build
    - run:
        name: Test App
        command: |
          git config --global url."https://${GITHUB_PERSONAL_ACCESS_TOKEN} :x-oauth-basic@github.com/".insteadOf "https://github.com/"
          dep ensure
          go test -v ./...
    - run:
        name: Push Image
        command: |
          if [[ "${CIRCLE_TAG}" =~ ^v[0.9]+(\.[0-9]+)*-[a-z]*$ ]]; then
            source deployment/dev/.env
            docker-compose -f deployment/dev/docker-compose.yml push
          else
            echo 'No tag, not deploying'
          fi
    - persist_to_workspace:
        root: .
        paths:
          - deployment/*
          - tools/*

当我将更改推送到分支时,每次构建Couldn't connect to Docker daemon at ... - is it running?到达构建作业的“构建应用程序”步骤时,构建都会失败。

请帮助我弄清楚为什么分支构建失败而标签构建没有失败。

2 个答案:

答案 0 :(得分:2)

我怀疑您遇到了docker-compose错误:https://github.com/docker/compose/issues/6050

当docker-compose文件中的映像名称无效时,该错误报告一个误导性错误(您得到的错误)。

如果将环境变量用作图像名称或图像标签,并且该变量是从分支名称设置的,则它将在某些分支而不是其他分支上失败。

答案 1 :(得分:0)

Save Version Number步骤上发生了问题。有时该版本为.${CIRCLE_BUILD_NUM},因为未传递任何标记。 Docker不喜欢以.开头的这些标签,因此我添加了条件检查以查看CIRCLE_TAG是否为空,如果是,请使用一些默认版本:v0.1.0-build