Unfortunately the only way I have found is listed here
to put the following in the buildAgent.properties file, like this:
env.MYVAR=%MYVAR%
env.MYVAR2=%MYVAR2%
The TeamCity Agent image is based on windows nanoserver, which isn't suitable for my needs so I have to create the buildagent.properties file myself (Not sure exactly how you would edit an existing file created automatically). To do so I'm using the following batch script, which I run as the entrypoint for my agent's docker container:
@echo off
::------------------------------
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set DTStamp=%YYYY%-%MM%-%DD%_%HH%-%Min%
::------------------------------
echo ##############################################################
echo Run-Agent.bat: %DTStamp%
echo ##############################################################
cd C:\BuildAgent\conf\
IF NOT EXIST buildagent.properties echo buildagent.properties not found - Creating buildagent.properties... && (
echo serverUrl=%SERVER_URL%
echo name=%AGENT_NAME%
echo workDir=../work
echo tempDir=../temp
echo systemDir=../system
echo authorizationToken=%AGENT_TOKEN%
echo env.MYVAR1=%MYVAR1%
echo env.MYVAR2=%MYVAR2%
echo env.MYVAR3=%MYVAR3%
) > buildagent.properties
echo running TeamCity Build Agent in background...
cd C:\BuildAgent\bin\
start /b service.start.bat
cd \
C:\Windows\System32\cmd.exe
@echo on
This seems to be working for me.