Error executing the kubectl set image command in Bitbucket Pipelines
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
The Bitbucket Pipeline build fails to execute the kubectl set image
command with the following error message:
1
error: all resources must be specified before image changes
Diagnosis
Command example:
1
- kubectl set image deployment/<service_name> <service_name>=$DOCKER_ECR_REPO_URL/<service_name>:${BITBUCKET_COMMIT} --user=$KUBE_USER_NAME --local=false
To troubleshoot this error, debug the build locally using the documentation: https://support.atlassian.com/bitbucket-cloud/docs/debug-pipelines-locally-with-docker/
If the build works as expected locally, it's most likely that the culprit is one of the variable values.
This error can happen if the variable (like DOCKER_ECR_REPO_URL)
value has unexpected whitespaces. It happens because Kubectl does the parsing of the key=value pairs provided as arguments in the command. If there is a whitespace at the beginning of the variable value, the command throws the error as the command can't parse the arguments properly.
Solution
The solution for this issue is to check and remove the whitespaces from the variable values.
Was this helpful?