I am writing a azure pipeline that will build a jar and a docker image. Most of part is working but I am not able to substitute $version variable in Dockerfile. And I am declaring artifact version as $(build.buildnumber)-$(build.sourcebranchname) as given below. I can not hard code it as with every run of build, builnumber will change. How can I use either $version or $(build.buildnumber)-$(build.sourcebranchname) in Dcokerfile where I am copying jar to container folder.
My generated artifact name is like this someservice-api-$(build.buildnumber)-$(build.sourcebranchname).jar
Azure Pipeline:
pool:
vmImage: 'windows-latest'
steps:
- task: DownloadSecureFile@1
displayName: 'Download gradle.properties secure file'
inputs:
secureFile: gradle.properties
- powershell: |
New-Item -Type Directory -Force "${HOME}/.gradle"
$version = "$(build.buildnumber)-$(build.sourcebranchname)"
Add-Content "$(Agent.WorkFolder)/_temp/gradle.properties" "`nartifactVersion=$version"
Add-Content "$(Agent.WorkFolder)/_temp/gradle.properties" "`nartifactDir=$path"
Copy-Item -Force "$(Agent.WorkFolder)/_temp/gradle.properties" "${HOME}/.gradle/gradle.properties"
other task like gradlew build, copy, publish to staging directory
Dockerfile:
FROM openjdk:8
WORKDIR /usr/src/webapp/clientscore
COPY ./build/libs/someservice-api-$version.jar api.jar
CMD ["java", "-jar", "api.jar"]
I have tried with following already
COPY ./build/libs/someservice-api-$version.jar api.jar
COPY ./build/libs/someservice-api-${version}.jar api.jar
COPY ./build/libs/someservice-api-$(build.buildnumber)-$(build.sourcebranchname).jar api.jar
COPY ./build/libs/someservice-api-${build.buildnumber}-${build.sourcebranchname}.jar api.jar
Azure Docker task:
- task: Docker@2
inputs:
command: 'buildAndPush'
Dockerfile: '**/Dockerfile'
The Azure task, Docker "BuildAndPush", that you are using does not accept build args. You need to define Docker "build" task then you can pass build args and use it accordingly in Dockerfile.
--build-arg varname="$(dynamicversion)"
Have a lookt at this
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments