小编jun*_*ent的帖子

circleci:如何为每个环境运行具有多个上下文的作业

我正在使用 circleCI 来部署生产或暂存环境。我想对与每个环境对应的每个分支的上下文使用相同的作业,因为我不喜欢为每个环境编写相同的代码。

我想像下面这样写。

version: 2
jobs:
  deploy:
    docker:
      - image: google/cloud-sdk
    steps:
      - checkout
      - run: <deploying commands>

workflows:
  version: 2
  deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only:
                - master
          context: production

      - deploy:
          filters:
            branches:
              only:
                - develop
          context: staging
Run Code Online (Sandbox Code Playgroud)

continuous-integration circleci-2.0

2
推荐指数
1
解决办法
2077
查看次数

你认为你可以重用 err 变量吗?

比如这种情况下,err 变量很快就会当场完成它的作用,所以我认为没有必要定义多个名称。

package main

func main() {
    foo, errFoo := foo()
    if errFoo != nil {
        panic(errFoo)
    }

    bar, errBar := bar()
    if errBar != nil {
        panic(errFoo)
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我将代码更改如下。

package main

func main() {
    foo, err := foo()
    if err != nil {
        panic(err)
    }

    bar, err := bar()
    if err != nil {
        panic(err)
    }
}
Run Code Online (Sandbox Code Playgroud)

你们都遵守什么规矩?

go

2
推荐指数
1
解决办法
1411
查看次数

标签 统计

circleci-2.0 ×1

continuous-integration ×1

go ×1