1

我正在尝试设置我的项目以部署 go 应用程序。当我尝试将 sed 与从作业传入的参数一起使用时 - 它工作正常当我尝试将 sed 与从作业传入的参数一起使用时,该参数被引用为上下文变量,它不起作用。看这个例子

version: 2.1
jobs:
  deploy-application:
    docker:
      - image: circleci/golang:1.13
        environment:
          GO111MODULE: "on"

    working_directory: /go/src/github.com/me/go-circle-elasticbeanstalk
    parameters:
      ebAppName:
        description: "The name to set the elastic beanstalk application to"
        default: "null"
        type: string
      elkHost:
        description: "The host to send logs to for elastic search"
        default: "null"
        type: string
    steps:
      - run: sudo apt-get -y -qq update
      - run: sudo apt-get install python-pip python-dev build-essential
      - run: sudo pip install awsebcli --upgrade
      - checkout
      - run: sed -i 's/MY-FLIGHTS-APP-PLACEHOLDER/<< parameters.ebAppName >>/g' .elasticbeanstalk/config.yml
      - run: sed -i 's/FILEBEAT-HOST-PLACEHOLDER/<< parameters.elkHost >>/g' .ebextensions/01_filebeat.config
      - run: ls -latr
      - run: go env
      - run: export GO111MODULE=on
      - run: go env
      - run: go build ./...
      - run: go build -o application server.go
      - run: ls -latr
      - run: ls -latr .elasticbeanstalk
      - run: zip my-server.zip application -r .ebextensions damien.test
      - run: ls -latr
      - run: eb deploy   
workflows:
    deploy-go-server:
      jobs:
      - deploy-application:
          name: deploy-dev
          ebAppName: my-flights-dev
          elkHost: $ELK_HOST
          filters:
            branches:
              only: develop
          context: my-dev
      - deploy-application:
          name: deploy-stage
          ebAppName: my-flights
          elkHost: $ELK_HOST
          filters:
            branches:
              only: stage
          context: my-stage

ebAppName 的值始终设置正确 但是,elkHost 的值始终显示为 $ELK_HOST 并且从不读取组织上下文值

我可以在这里做些什么来解决这个问题有什么帮助吗?我已经在另一个项目中使用了这种方法并且效果很好

任何帮助表示赞赏

干杯达米安

4

1 回答 1

1

如果要将参数作为 var 名称发送,请使用类型 env_var_name,或者${EB_APP_NAME}如果参数类型为字符串,则在运行工作流时解析参数。

version: 2.1
jobs:
   build:
     parameters:
       elkHost:
         type: env_var_name
         default: ELK_DEFAULT_HOST # Note: replace with env var (without $) or remove it if the param is mandatory.
       ebAppName:
         type: string
         default: 'my-app-name'
     docker:
       - image: ubuntu:latest
     steps:
       - run: |
           echo "--elkHost ${<< parameters.elkHost >>} \\
                 --ebAppName << parameters.ebAppName >>"
workflows:
  workflow:
    jobs:
      - build:
          elkHost: ELK_HOST
          ebAppName: ${EB_APP_NAME}
于 2020-05-10T11:59:16.323 回答