go - 仅在合并到 master 时运行任务

标签 go circleci

我使用以下配置,它按预期工作,它在每个 PR 上运行命令或合并到主服务器,现在我想进行一些集成测试,我想仅在合并到主服务器时运行,所有 PR 都应该保持不变(并像以前一样运行以下配置)。这里的细微差别是,对于集成测试,我需要其他 docker 图像和不同的运行命令来执行(应该只在合并到 master 时执行),是否可以使用 CircleCI 来完成? p>

# Golang CircleCI 2.0 configuration file
version: 2
jobs:
  build:
    docker:
      # specify the version
      - image: circleci/golang:1.11
    working_directory: /go/src/sbr
    steps:
      - checkout
      - run: go version
      - run: go env
      - run: go get -v -t -d ./...
      - run: go test -v ./...

我尝试在现有的 docker 镜像下添加另一个 docker 镜像,但出现错误

更新:

version: 2
jobs:
  build:
    docker:
      - image: circleci/golang:1.11
    working_directory: /go/src/sbr
    steps:
      - checkout
      - run: go version
      - run: go env
      - run: go get -v -t -d ./...
      - run: go test -v ./...

  test-integration:
    docker:
      - image: other-image

workflows:
  version: 2
  builds:
    jobs:
      - build

  integration-test:
    jobs:
      - test-integration:
          requires:
            - build
          filters:
            branches:
              only: master

这里的问题是我在将 require

添加到第二个工作流时出错
  requires:
    - build 

我希望测试test-integration 时,它还会根据要求运行build 作业。我做错了什么?

错误是:

requires job \"build\" but \"build\" is not part of this workflow.
# At least one job in the workflow must have no dependencies.
# The following jobs are unreachable: integration
# 
# -------

# Don't rerun this job. Rerunning will have no effect.
false

最佳答案

您的配置只有一个名为 build 的作业,没有工作流。听起来您想要的是为集成测试运行第二个作业,并且仅在分支为 master 时才运行第二个作业。要完成这两个任务,您将使用包含两个作业的工作流程。

参见 https://circleci.com/docs/2.0/configuration-reference/#workflows

一个可能看起来像的例子:

jobs:
  build:
    docker:
     - image: circleci/golang:1.11
    ...

  test-integration:
    docker:
      - image: other-image
    ...

workflows:
  version: 2
  workflow-name:
    jobs: 
      - build
      - test-integration:
          filters:
            branches:
              only: master

关于go - 仅在合并到 master 时运行任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54373567/

相关文章:

mongodb - 从接口(interface)类型的mongodb游标解码值

go - 从给定范围生成组合

java - CircleCI + Gradle + Heroku 部署

postgresql - 如何使用 SSL/TLS 在 CircleCI 中运行 PostgreSQL?

android - Circle CI 无法在存储库容器上找到参数 [] 的方法 google()

CSS 文件未被引用

javascript - 到特定房间的 Websocket 消息 - Golang Kataras/Iris

go - Golang在函数中使用结构的全局变量中的设置变量

angular - 我需要在 CI 作业中缓存什么以避免每次 ngcc 重新编译?

android - Gradle 测试不工作 : Could not determine the dependencies of task ':app:testReleaseUnitTest'