On jenkins-x.yaml pipeline sh: export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml won't correctly translate any modification made on project's skaffold.yaml.
Modify anything on skaffold.yaml like:
apiVersion: skaffold/v1beta13
kind: Config
build:
artifacts:
- image: repo/app_name
context: .
docker:
buildArgs:
PROD: "true" # THIS IS NEW
...
jx step syntax effective should translate build-container-build step into:
- args:
- --build-arg=PROD=true # <--- this should be included
- --cache=true
- --cache-dir=/workspace
- --context=/workspace/source
- --dockerfile=/workspace/source/Dockerfile
- --destination=gcr.io/repo/app_name:${inputs.params.version}
- --cache-repo=gcr.io/repo/cache
command: /kaniko/executor
dir: /workspace/source
image: gcr.io/kaniko-project/executor:9912ccbf8d22bbafbf971124600fbb0b13b9cbd6
name: build-container-build
jx step syntax effective simply does not read the local skaffold.yaml file and outputs this:
- args:
- --cache=true
- --cache-dir=/workspace
- --context=/workspace/source
- --dockerfile=/workspace/source/Dockerfile
- --destination=gcr.io/repo/app_name:${inputs.params.version}
- --cache-repo=gcr.io/repo/cache
command: /kaniko/executor
dir: /workspace/source
image: gcr.io/kaniko-project/executor:9912ccbf8d22bbafbf971124600fbb0b13b9cbd6
name: build-container-build
Important! jx step syntax effective will output the same thing even if you make syntax errors or delete skaffold.yaml from your project.
The output of jx version is:
~ jx version
NAME VERSION
jx 2.0.712
Kubernetes cluster v1.13.7-gke.24
kubectl v1.15.1
helm client Client: v2.14.2+ga8b13cc
git 2.22.0
Operating System Mac OS X 10.12.6 build 16G2128
Posted a workaround on slack, I am also sharing it here.
You will need jx platform with skaffold >= 0.33.0. E.g. jx platform version 2.0.1125 has skaffold 0.37.0. BUT I stubled upon this bug (https://github.com/jenkins-x/jx/issues/4501) when using it. So the solution for me was to use jenkins x platform version 2.0.1012 and use sed commands for setting specific build args in the skaffold.yaml
E.g.: sed -i -e "s|PROD: {{.PROD_BOOL}}|PROD: false|" skaffold.yaml
Where PROD: {{.PROD_BOOL}} is what you will have in your skaffold script prior to executing sed
More info: https://github.com/GoogleContainerTools/skaffold/releases/tag/v0.33.0
"Support buildArgs with useDockerCLI=false"
Considering the commit 684902d9fbbe5a4316da01a4bef2a3331150a505, we can clearly see that when kaniko: true for jx boot - jx-requirements.yaml, it finds the expression skaffold build in the effective jenkins-x.yaml and then makes a replacement for a standard (and unparameterized) Kaniko build, this is somewhat misleading to people unaware of this behavior as I had to dig for that commit after noticing this pattern. At first I thought that jx had any sort of "skaffold to kaniko" translation but it's actually not the case here, its just a command replacement.
In the end, providing buildArgs on skaffold will not do a thing because the file is ignored.
I'll try to disable kaniko or write a kaniko command with buildArgs myself, that's how I might fix my issue though this opens an opportunity for enhancement @jstrachan.
Though this issue might be useful to someone, I'm closing this.
Trying to figure out how to set build args or modify artifact names... anyone know seems how it sounds like changing this skaffold file won't do it?
Most helpful comment
Considering the commit 684902d9fbbe5a4316da01a4bef2a3331150a505, we can clearly see that when
kaniko: trueforjx boot - jx-requirements.yaml, it finds the expressionskaffold buildin the effectivejenkins-x.yamland then makes a replacement for a standard (and unparameterized) Kaniko build, this is somewhat misleading to people unaware of this behavior as I had to dig for that commit after noticing this pattern. At first I thought that jx had any sort of "skaffold to kaniko" translation but it's actually not the case here, its just a command replacement.In the end, providing buildArgs on skaffold will not do a thing because the file is ignored.
I'll try to disable kaniko or write a kaniko command with buildArgs myself, that's how I might fix my issue though this opens an opportunity for enhancement @jstrachan.
Though this issue might be useful to someone, I'm closing this.