sdk-container-builds
sdk-container-builds copied to clipboard
How to use `-p ContainerImageTags` flag properly in Gitlab CI pipeline with multiple tags
I have found https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container?pivots=dotnet-8-0, https://github.com/dotnet/sdk-container-builds/issues/311 and https://github.com/dotnet/sdk-container-builds/issues/236, but still don't know how I can configure multiple container image tags while using a version environment variable.
Using: Net 8, latest version in Gitlab CI
What works:
$ dotnet publish -c Release --self-contained --no-restore --output publish/ -p ContainerImageTags="${VERSION}" /t:PublishContainer
What doesn't work:
- Adding
latestat the end:
$ dotnet publish -c Release --self-contained --no-restore --output publish/ -p ContainerImageTags="${VERSION};latest" /t:PublishContainer
MSBUILD : error MSB1006: Property is not valid.
Switch: latest
For switch syntax, type "MSBuild -help"
- Adding
latestat the front:
$ dotnet publish -c Release --self-contained --no-restore --output publish/ -p ContainerImageTags="latest;${VERSION}" /t:PublishContainer
MSBUILD : error MSB1006: Property is not valid.
Switch: latest
For switch syntax, type "MSBuild -help"
- Using double quotes as described in the
publish-as-containerreference page:
$ dotnet publish -c Release --self-contained --no-restore --output publish/ -p ContainerImageTags='"latest;${VERSION}"' /t:PublishContainer
/usr/share/dotnet/sdk/8.0.403/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010:
Invalid ContainerImageTags provided: ${VERSION}.
ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period.
- Using double quotes as described in the
publish-as-containerreference page (With latest as second parameter):
$ dotnet publish -c Release --self-contained --no-restore --output publish/ -p ContainerImageTags='"${VERSION};latest"' /t:PublishContainer
/usr/share/dotnet/sdk/8.0.403/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010:
Invalid ContainerImageTags provided: ${VERSION}.
ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period.
- With a combined environment variable as suggested in some of the other issues:
$ export ContainerImageTags='latest;${VERSION}'
$ dotnet publish -c Release --self-contained --no-restore --output publish/ /t:PublishContainer
/usr/share/dotnet/sdk/8.0.403/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010:
Invalid ContainerImageTags provided: ${VERSION}.
ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period.
- With a combined environment variable as suggested in some of the other issues (With latest as second parameter):
$ export ContainerImageTags='${VERSION};latest'
$ dotnet publish -c Release --self-contained --no-restore --output publish/ /t:PublishContainer
/usr/share/dotnet/sdk/8.0.403/Containers/build/Microsoft.NET.Build.Containers.targets(113,5): error CONTAINER2010:
Invalid ContainerImageTags provided: ${VERSION}.
ContainerImageTags must be a semicolon-delimited list of valid image tags. Image tags must be alphanumeric, underscore, hyphen, or period.
I don't want to (and I can't since the version is taken from the Git tags using https://github.com/GitTools/GitVersion) put the tags directly to the project, but I want to always get two tags: Version (e.g. 1.14.2) and latest. Any ideas what else I can test?
Specifying ContainerImageTags under variables in the Gitlab CI template worked for me:
variables:
ContainerImageTags: latest;${VERSION}
script:
- dotnet publish $PROJECT_DIR -p PublishProfile=DefaultContainer -p ContainerBaseImage=$CONTAINER_BASE_IMAGE -p ContainerRepository=$CONTAINER_REPOSITORY -p ContainerRegistry=$CI_REGISTRY
Output snippet:
Uploading tag 'latest' to 'registry.gitlab.com'.
Uploaded tag 'latest' to 'registry.gitlab.com'.
Uploading tag '0.1.387' to 'registry.gitlab.com'.
Uploaded tag '0.1.387' to 'registry.gitlab.com'.
Specifying
ContainerImageTagsundervariablesin the Gitlab CI template worked for me:variables: ContainerImageTags: latest;${VERSION} script: - dotnet publish $PROJECT_DIR -p PublishProfile=DefaultContainer -p ContainerBaseImage=$CONTAINER_BASE_IMAGE -p ContainerRepository=$CONTAINER_REPOSITORY -p ContainerRegistry=$CI_REGISTRYOutput snippet:
Uploading tag 'latest' to 'registry.gitlab.com'. Uploaded tag 'latest' to 'registry.gitlab.com'. Uploading tag '0.1.387' to 'registry.gitlab.com'. Uploaded tag '0.1.387' to 'registry.gitlab.com'.
This works. I had to use it a bit differently, e.g. export ContainerImageTags="latest;${VERSION}" && dotnet publish.... However, I will keep this issue open as it's a clear bug for me.