首页 > 解决方案 > 如何在 CircleCI 任务中访问构建 ID

问题描述

我正在尝试运行sed命令来替换指示当前构建 ID 的环境变量。根据文档CIRCLE_BUILD_NUM包含我正在寻找的值,根据这个例子,它应该非常容易在command.

下面是配置文件,下面是正在执行命令的bundle.gradle文件,下面是结果。sed如您所见,该sed命令只是CIRCLE_BUILD_NUM将其视为字符串而不是获取内部版本号。

配置.yml

version: 2.1

orbs:
android: circleci/android@0.2.0

jobs:
build:
  executor: android/android

  steps:
    - checkout
    - setup_remote_docker: 
        docker_layer_caching: true      
    - run:
        name: testing env vars
        command: sed 's/${BUILD_NUM_1}/${CIRCLE_BUILD_NUM}/g' -i build.gradle 

捆绑包.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
def buildNum = ${BUILD_NUM_1}

输出

// Top-level build file where you can add configuration options common to all sub-projects/modules.
def buildNum = ${CIRCLE_BUILD_NUM}

标签: sedcirclecicircleci-2.0circleci-workflows

解决方案


以下sed命令有效。

 - run:
     name: testing env vars
     command: sed "s/_buildNum/${CIRCLE_BUILD_NUM}/g" -i build.gradle 

推荐阅读