msbuild runner doesnt respect rewritten env.BUILD_NUMBER

Answered

Hello everyeone!

Running Teamcity Pro  2019.2 (build 71499)

I have set the Build number format: to "Not set yet"

then, the 1st build step rewrites the env.BUILD_NUMBER :
```
curl  -XPUT --header "Content-Type: text/plain" %teamcity.serverUrl%/app/rest/builds/%teamcity.build.id%/number -d "NEW_NUM"
echo "##teamcity[setParameter name='env.BUILD_NUMBER' value='NEW_NUM']"

```

the 2nd step runs the msbuild runner with the build file content:
```

...

<Target Name="Build">
   <Message text="BUILD_NUMBER is $(BUILD_NUMBER)" Importance="high" />
...
```

And the output is:
  BUILD_NUMBER is Not set yet

while should be NEW_NUM

 

the content of runtime generated test.proj.teamcity.msbuild.tcargs is

...

/target:Build
"/logger:JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger,D:\TeamCityAgents\buildAgent1\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MSBuildLoggers.4.0.dll"
/property:build_number="Not set yet"
...

 

I've also tried pass the /p:build_number="NEW_NUM" without success.

 

4 comments
Comment actions Permalink

Hi,

 

is there any reason why you are passing the parameters via curl and then using "setParameter" instead of directly impacting the build number via the respective service message? https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingBuildNumber

 

I've tested a first command line that passes the "buildNumber" message and my tcargs file had the updated value instead. It should also update the env var as far as I am able to tell.

0
Comment actions Permalink

The curl is just a second method shown. I'v tried both - curl and service message with the same result.

I've tried right now again, and the problem still persists:

For the build.proj content:

...

<Target Name="Build">
    <Message text="BUILD_NUMBER is $(BUILD_NUMBER)" Importance="high" />
    <Exec Command="cmd.exe /c echo %BUILD_NUMBER%"/>
</Target>

...

..The console output
...

[test.proj.teamcity] Build
[11:30:47][Build] BUILD_NUMBER is Not set yet
[11:30:47][Build] Exec
[11:30:47][Exec] cmd.exe /c echo %BUILD_NUMBER%
[11:30:47][Exec] NEW_NUM
 
 
 
The test.proj.teamcity.msbuild.tcargs contains
 
/property:build_number="Not set yet"
...
0
Comment actions Permalink

Just to be clear, what is the service message you are sending? I saw in your original post that you had both curl and a service message, but there is a specific one, "buildNumber" that is the one I tested. As far as I am aware, that one should work, but on the same fashion, what you currently have should still pick up the environment variable. Also, on your last post you added "echo %BUILD_NUMBER%" instead of "echo %env.BUILD_NUMBER%"

 

Please, check the following after fixing the issue mentioned above (run a new build afterwards):

On the build results, check the Parameters tab on the results page, and locate there the multiple references to build number, especially but not exclusively the environment variables section, see if they were updated or not. 

If the parameters were correctly updated by the end of the build, does the build still show the incorrect messages? Could you share a screenshot of the build steps overview?

If the parameters were not updated, there is something wrong about how your build is reporting the service message. Could you please share your exact build step where you run it?

0
Comment actions Permalink

oh, sorry, i tried again and it works fine with the service message you mension.

Thanks for the replies, problem solved :)

0

Please sign in to leave a comment.