Created
May 6, 2019 19:13
-
-
Save esauser/d8e937568e93dce902b0984abcab8690 to your computer and use it in GitHub Desktop.
Concourse Windows Worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
nuget restore -Verbosity normal | |
if %errorlevel% neq 0 exit /b %errorlevel% | |
msbuild -p:Configuration=Release ^ | |
-p:WarningLevel=0 | |
if %errorlevel% neq 0 exit /b %errorlevel% | |
dotnet.exe test TestProject.csproj --configuration Release --no-build -v n | |
if %errorlevel% neq 0 exit /b %errorlevel% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- task: build | |
config: | |
platform: windows | |
inputs: | |
- name: input | |
outputs: | |
- name: output | |
run: | |
path: runDockerImage.bat | |
params: | |
DOCKER_IMAGE: mcr.microsoft.com/dotnet/framework/sdk:4.7.2 | |
WORKING_DIRECTORY: input | |
SCRIPT_PATH: build.bat | |
ENV_ENVIRONMENT_VARIABLE: 1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set DOCKER_IMAGE 1>NUL 2>NUL | |
if errorlevel 1 echo DOCKER_IMAGE environment variable must be set && exit /b 1 | |
set SCRIPT_PATH 1>NUL 2>NUL | |
if errorlevel 1 echo SCRIPT_PATH environment variable must be set && exit /b 1 | |
for /f "tokens=*" %%G in ('dir /b') do call set volumes=%%volumes%% -v "%cd%\%%G:C:\Concourse\%%G" | |
if errorlevel 1 exit /b %errorlevel% | |
echo. 2>environmentVariables.txt | |
if errorlevel 1 exit /b %errorlevel% | |
for /f "tokens=*" %%G in ('set ^| findstr ENV_') do echo %%G >> environmentVariables.txt | |
if errorlevel 1 exit /b %errorlevel% | |
powershell -Command "(gc environmentVariables.txt) -replace 'ENV_', '' | Out-File environmentVariables.txt -Encoding ascii" | |
if errorlevel 1 exit /b %errorlevel% | |
set WORKING_DIRECTORY 1>NUL 2>NUL | |
if errorlevel 1 (set workingDirectory=Concourse && cmd /c "exit /b 0") else (set workingDirectory=Concourse\%WORKING_DIRECTORY%) | |
if errorlevel 1 exit /b %errorlevel% | |
docker pull %DOCKER_IMAGE% | |
if errorlevel 1 exit /b %errorlevel% | |
docker run ^ | |
--entrypoint "%SCRIPT_PATH%" ^ | |
-w "C:\%workingDirectory%" ^ | |
%volumes% ^ | |
--env-file environmentVariables.txt ^ | |
--rm ^ | |
%DOCKER_IMAGE% | |
if errorlevel 1 exit /b %errorlevel% |
thanks!
This was really helpful. Thank you very much..
Just some correction I would suggest:
While setting environment variables, set like
for /f "tokens=*" %%G in ('set ^| findstr ENV_') do echo %%G>> environmentVariables.txt
Instead of
for /f "tokens=*" %%G in ('set ^| findstr ENV_') do echo %%G >> environmentVariables.txt
Note the space before >>
So that, all environment variable' values don't have a space at the end of them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
runDockerImage.bat run the
SCRIPT_PATH
within theDOCKER_IMAGE
mounting all inputs and outputs, setting the optionalWORKING_DIRECTORY
, and anyENV_
params as environment variables, trimming theENV_
. Since the container is ran with--rm
it is destroyed upon error completion. The only known scenario not handled is when a job is interrupted the container continues until it either completes or errors.