【问题标题】:Configure yaml file for circle CI including envionment variables for an Angular project为 circleCI 配置 yaml 文件,包括 Angular 项目的环境变量
【发布时间】:2018-12-18 05:47:09
【问题描述】:

我有一个正在尝试构建的项目,但我的 .api-keys 文档正在被 gitignored。

所以,我将我的密钥作为环境变量添加到 circle CI 上的项目中。

我的问题是我不太确定在哪里/如何让我的 yaml 配置脚本知道它们是什么:

旧配置脚本:

version: 2.1
orbs:
  cypress: cypress-io/cypress@1.0.1
workflows:
  build:
    jobs:
      - cypress/install:
          build: 'npm run build'
      - cypress/run:
          requires:
            - cypress/install
          start: 'npm start'

我想添加的行(我想?):

environment: 
    masterFirebaseConfig: $masterFirebaseConfig

这是正确的做法吗?上面的 yaml 这行应该放在哪里?

非常感谢任何提示!

2018 年 12 月 29 日更新:

我将我的 api-keys.ts 文件更新为:

export var masterFirebaseConfig = {apiKey: $fireBaseApiKey, authDomain: 'dataJitsu.firebaseapp.com',databaseURL: 'https://datajitsu.firebaseio.com',storageBucket: '',messagingSenderId: '495992924984'};
export var masterStripeConfig = {publicApiTestKey: $masterStripePublicApiKey,secretApiTestKey: $masterStripeSecretApiKey,publicApiKey: '',secretApiKey: ''};

其中 $fireBaseApiKey、$masterStripePublicApiKey 和 $masterStripeSecretApiKey 是我添加到项目中的环境变量。

这似乎也不起作用:

src/app/api-keys.ts(1,44) 中的错误:错误 TS2304:找不到名称 '$fireBaseApiKey'。 src/app/api-keys.ts(2,52):错误 TS2304:不能 找到名称“$masterStripePublicApiKey”。 src/app/api-keys.ts(2,96): 错误 TS2304:找不到名称“$masterStripeSecretApiKey”。

【问题讨论】:

    标签: angular circleci circleci-2.0


    【解决方案1】:

    如果您已经在 CircleCI 中将密钥添加为环境变量,那么它们已经可用于您的构建作业。只需按名称引用它们,(例如$MY_PRECIOUS_KEY)。

    如果您想覆盖现有值或设置新值,您只需要set an environment variable in your config script

    【讨论】:

    • 谢谢。不过,没有骰子(请参阅我即将对该问题进行的更新)。
    • 你试过debug with SHH吗?请登录您的容器并检查变量是否正确设置,键入echo $masterStripePublicApiKey。请记住,环境变量区分大小写。
    • 我刚开始尝试这个。我已经 ssh 进入会话并查看了日志文件,但没有看到任何回显。
    • 刚刚在这里问了一个相关问题:stackoverflow.com/questions/54263826/…
    【解决方案2】:

    我在 VSTS 上为我的 Angular 项目实现了这种 CI-CD,并使用以下方式进行部署。

    这里是build.yaml文件的配置

    resources:
    - repo: self
    queue:
      name: Hosted VS2017
      condition: succeeded()
      demands: npm
    
    steps:
    - task: Npm@1
      displayName: npm install
      inputs:
        verbose: false
    
    - task: Npm@1
      displayName: npm custom
      inputs:
        command: custom
        verbose: false
        customCommand: 'run build'
    
    - task: ArchiveFiles@2
      displayName: Archive dist
      inputs:
        rootFolderOrFile: dist
        includeRootFolder: false
    
    - task: PublishBuildArtifacts@1
      displayName: Publish Artifact: drop
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    

    我专门创建了如下的部署文件环境。这是一个 QA 实例。

    apiVersion: v1
    kind: Service
    metadata:
      name: portal
      labels:
        app: portal
    spec:
      loadBalancerIP: 104.210.66.49
      type: LoadBalancer
      ports:
      - port: 80
        name: http
      selector:
        app: portal
    ---
    apiVersion: apps/v1 
    kind: Deployment
    metadata:
      name: portal
    spec:
      selector:
        matchLabels:
          app: portal
      replicas: 1 
      template: 
        metadata:
          labels:
            app: portal
        spec:
          containers:
          - name: portal
            image: yourdomain.azurecr.io/portal
            ports:
            - containerPort: 80
            env:
            - name: IdentityServerAuthentication__Authority
              value: http://id.qa.yourdomain.com  # Identity URL
            - name: env
              value: qa
          imagePullSecrets:
            - name:  projectqaregistry  # Registry file name
    ---
    

    To setup a build for Circle CI you can take a reference from here

    【讨论】:

    • 谢谢,@Dipak!这个配置。文件与我的如此不同,以至于我无法从中提取有用的信息。看起来您确实在配置脚本中使用了环境变量,但我没有看到它与问题中我的项目配置文件的关系。
    猜你喜欢
    • 2022-11-28
    • 2019-06-13
    • 1970-01-01
    • 2021-07-14
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    相关资源
    最近更新 更多