0

I am trying to build a docker container with the atlassian-build-runner but make it configurable to specify either latest version (w/o suffix) or latest version using a suffix using the following snippet:

ARG BASE_IMAGE=mcr.microsoft.com/dotnet/framework/sdk:4.8
FROM $BASE_IMAGE

...

# Install Atlassian build, specify --build-arg=-x.y to use different version than latest release
ARG BUILDER_VERSION=""
ADD https://product-downloads.atlassian.com/software/bitbucket/pipelines/atlassian-bitbucket-pipelines-runner$BUILDER_VERSION.zip bitbucket-pipelines-runner.zip
RUN powershell -Command Expand-Archive bitbucket-pipelines-runner.zip C:\bitbucket-pipelines-runner

I would like the user to not have to specify a leading dash (-) in the build argument. Any pointers on how to do this on a Windows container?

I already tried modifying the environment variable in PowerShell (default shell for the Windows base image) to no avail:

ARG BUILDER_VERSION=""
ENV BUILDER_VERSION=$BUILDER_VERSION
ENV if ([string]::IsNullOrEmpty($Env:BUILDER_VERSION)) { return "-" + $Env:BUILDER_VERSION}

But it keeps failing the download since the dash is missing when a version build argument is supplied. Any pointers?

Jonathan
  • 748
  • 3
  • 20
  • I suspect this isn't possible: you can't run conditionals or other code inside an `ENV` statement, and Compose only supports very limited [variable expansion](https://docs.docker.com/compose/compose-file/compose-file-v3/#variable-substitution) syntax. – David Maze May 19 '22 at 09:52
  • It seems with linux containers some form of conditional statement is possible, see https://stackoverflow.com/a/43656644/2186184 – Jonathan May 19 '22 at 12:04
  • 1
    That answer has an ordinary Bourne shell conditional _within a single `RUN` statement_; that can't set persistent environment variables, and anything it sets (Bourne shell `export` directive) would get reset at the end of the `RUN` statement. – David Maze May 19 '22 at 13:14

0 Answers0