Azure Spring Apps Custom Container Image CICD deployment using Azure DevOps

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Since 2022 May, Azure Spring Cloud started to allow deploying an application with a custom container image (Preview).

Deploying an application with a custom container supports most features as when deploying a JAR application. Other Java and non-Java applications can also be deployed with the container image.


This blog aims to show an example for how to use Azure DevOps pipeline to make CICD deployment using custom container image.




Step 1: Create a Git repo for your project in Azure DevOps


1.  Go to 

2.  After signing in, click on 'Create Project' in the top right of the screen. If there is no organization already created then this will need to be done first.

3.  Create a Git repository in your Azure DevOps Project.


Get the repository URL



Step 2: Push Application code and Dockerfile to the git repository


1.  Git clone the new created empty repository to your local machine


git clone​



2.  Add your application code and Dockerfile

    In this example I build a simple Python Flask application, and use a Dockerfile to pack it into a custom docker container.

    There are 3 files need to be committed to the Git repo.






from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello from Azure Spring Cloud Custom Container Image!"




FROM python:3.8-slim-buster WORKDIR /flaskdemo COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt COPY . . EXPOSE 1025 CMD [ "python3", "-m" , "flask", "run", "--host=", "--port=1025"]



3.  Push your code to DevOps git repository


git add . git commit -m "initial commit" git push





Step 3: Create a new Build Pipeline to build and push Docker image

1.  Create a new pipeline use the classic editor



2. Select source repository



3. Select Docker container template



4.  Fill in your Azure Container Registry information in the "Build an image" Task.
Since we added our Dockerfile in our git repository, according to "**/Dockerfile" setting, the pipeline can find our Dockerfile and use it to build the docker image.



5.  Fill in your Azure Container Registry information in the "Push an image" Task.



6. Enable continuous integration in Triggers



Step 4: Create New Release Pipeline

1.  Set the Artifacts, select your project name, Source (the build pipeline we just created in Step 3)


We can enable Continuous deployment trigger, so when there is any code change being pushed to our git repository, the release task will be triggered to run.



2. Add a new Stage using "Empty job" template, named it "Deploy to App"



3. Create a Task in this "Deploy to App" stage



4. Select "ubuntu-latest" as the job Agent



5.  Add an Azure CLI task in this Agent job



6. Select your Azure subscription, and fill in the following Shell Inline script


az config set extension.use_dynamic_install=yes_without_prompt az extension add --name spring-cloud az spring-cloud app deploy \ --resource-group <your resource group name> \ --name <App name> \ --container-image $(Build.Repository.Name):$(Build.BuildId) \ --service <your Azure Spring Cloud service name> \ --container-registry <Azure Container Registry url> \ --registry-password <Azure Container Registry password> \ --registry-username <Azure Container Registry username>





Step 5: Trigger CICD docker image build and App deployment.

Since we enabled continuous integration in Step 3 & continuous deployment in Step 4, when we commit and push any code change in the git repository, the pipeline will be automatically triggered.


1. Push some changes in the git repo, then we can go to Pipeline -> Runs to check the build log



2. We can see detailed log for each build step





3. We can go to Pipeline -> Releases to check the release log


"Azure CLI" task log records all the Azure CLI commands and the response details.




4. After the new app deployment being successfully boot up, in Azure Spring Apps portal, we should be able to see Succeeded Provisioning state.


In the App -> Configuration portal, we should see the new custom docker image being set.


We can check the application being successfully brought up and responding incoming requests. 


Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.