首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅在合并到主服务器时才运行任务

仅在合并到主服务器时才运行任务
EN

Stack Overflow用户
提问于 2019-01-25 22:21:48
回答 1查看 1.2K关注 0票数 1

我使用了如下的配置,如预期的那样,它在每个PR上运行命令或合并到主服务器,现在我想进行一些集成测试,只有在合并到主时才能运行,所有的PR都应该保持不变(并像以前一样运行下面的配置)。这里的细微之处在于,对于集成测试,我需要其他的坞映像和不同的运行命令来执行(只有在合并到主服务器时才能执行),是否可以用CircleCI执行呢?

代码语言:javascript
复制
# 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 ./...

我试图在现有的图像下添加另一个对接者图像,但是我得到了错误。

更新:

代码语言:javascript
复制
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添加到第二个工作流时出现了错误

代码语言:javascript
复制
  requires:
    - build 

我希望测试test-integration之前,它还将按请求运行build作业。我做错什么了?

错误是:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-26 17:55:34

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

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

这可能是什么样子的一个例子:

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54373567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档