Hi,
I have created a bitbucket pipeline like below and now able to push image to container registry with build number as tag.
But failing to pull the same image in kubernetes deployment yml.
pipeline.yml
steps:
- step: &Build
name: Build and publish docker image.
services:
- docker # Enable Docker for your repository
image: maven:3.6.1-jdk-8
script:
- mvn -DskipTests -B package # -B batch mode makes Maven less verbose
- export IMAGE_NAME=$REGISTRY_NON_PROD/$SERVICE_NAME:${BITBUCKET_BUILD_NUMBER}
- docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_PASSWORD $REGISTRY_NON_PROD
- docker build -t $REGISTRY_NON_PROD/$SERVICE_NAME:${BITBUCKET_BUILD_NUMBER} .
- docker push $IMAGE_NAME
- step: &Deploy
image:
name: atlassian/default-image:2
name: Deploy Image
trigger: manual
script:
- sed -i "s|{{image}}|$IMAGE_NAME|g" aks-deployment.yaml
- pipe: microsoft/azure-aks-deploy:1.0.2
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
AZURE_AKS_NAME: $AZURE_AKS_NAME
AZURE_RESOURCE_GROUP: $AZURE_RESOURCE_GROUP
KUBECTL_COMMAND: 'apply'
KUBECTL_ARGUMENTS: '-f aks-deployment.yaml'
aks-deployment.yaml
containers:
- name: containername
image: {{image}}
imagePullPolicy: IfNotPresent
on trying to deploy this am getting error like
'The CronJob "jobname" is invalid: spec.jobTemplate.spec.template.spec.containers[0].image: Required value'
Can someone please help with this.
Thanks in advance !
Hi @Reethu
Thank you for your question!
To make image name flexible try envsubst (the program substitutes the values of environment variables) instead:
- envsubst < aks-deployment.yaml.template > aks-deployment.yaml
Add to your repository template aks-deployment.yaml.template file:
containers:
- name: containername
image: ${IMAGE_NAME}
imagePullPolicy: IfNotPresent
Note! Make sure that ${IMAGE_NAME} exists in the step environment.
Also, good example provided in example-google-gke-kubectl-run repository.
Cheers,
Oleksandr Kyrdan
Note! For future maintenance purposes we have forked the microsoft/azure-aks-deploy pipe from https://bitbucket.org/microsoft/azure-aks-deploy.
Now it is available as atlassian/azure-aks-deploy:1.0.2:
script:
- pipe: atlassian/azure-aks-deploy:1.0.2
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
AZURE_AKS_NAME: 'my-cluster'
AZURE_RESOURCE_GROUP: 'my-resource-group'
KUBECTL_COMMAND: 'version'
To discover more pipes, visit our Bitbucket Pipes Marketplace.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Oleksandr .
- step: &Deploy
image:
name: atlassian/default-image:2
name: Deploy Image
trigger: manual
script:
- export Build_Id=${BITBUCKET_BUILD_NUMBER}
- envsubst < aks-deployment.yaml > aks.yaml
- pipe: atlassian/azure-aks-deploy:1.0.2
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
AZURE_AKS_NAME: $AZURE_AKS_NAME
AZURE_RESOURCE_GROUP: $AZURE_RESOURCE_GROUP
KUBECTL_COMMAND: 'apply'
KUBECTL_ARGUMENTS: '-f aks.yaml'
DEBUG: 'true'
I have aks-deployment.yaml in my repository with the variable ${Build_Id}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, it's better to create the template file in your repository.
You don't need destination file anymore.
Destination file will be generated automatically on each build.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.