Reading CIRCLE_BUILD_NUM from cmd.exe shell

I am new to CircleCI, having mainly used TFS and Jenkins for previous work, and am having difficulty reading the built-in environment variables, such as CIRCLE_BUILD_NUM.

I would like to pass this in a command as an argument to MSBuild, but everything I have tried doesn’t seem to work ?

version: 2.1

orbs:
win: circleci/windows@2.4.1

jobs:
build:
executor:
name: win/default
size: “medium”
shell: cmd.exe
steps:
- checkout
- run:
name: Run build
command: |
msbuild CircleBuild.proj /p:Revision=$CIRCLE_BUILD_NUM /maxcpucount:1 /target:FullBuild /fl1 /fl2 /fl3

I’ve tried $CIRCLE_BUILD_NUM, ${CIRCLE_BUILD_NUM} but this just results in the literal value being passed rather than the actual number of the build

Is there an example I can look at somewhere, it seems there is very little in the way of examples for windows builds to be found

Hi @MirageMike. Welcome to the CircleCI Discuss community!

When using the Command Prompt (shell: cmd.exe), the correct syntax is: %*variable_name*%.

So in your case: %CIRCLE_BUILD_NUM%

- run:
    name: Run build
    command: |
        msbuild CircleBuild.proj /p:Revision=%CIRCLE_BUILD_NUM% /maxcpucount:1 /target:FullBuild /fl1 /fl2 /fl3
1 Like

that did the trick thanks - would be great if an example for it was on the main docs page for these

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.