Build and deploy Java to Azure Functions

Azure Pipelines

You can use Azure Functions to run small pieces of code in the cloud without the overhead of running a server. In this step-by-step guide you'll learn how to create a pipeline that continuously builds and deploys a your Java function app. Your team can then automatically build each commit in GitHub, and if you want, automatically deploy the change to Azure Functions.


  • A GitHub account, where you can create a repository. If you don't have one, you can create one for free.

  • An Azure DevOps organization. If you don't have one, you can create one for free. (An Azure DevOps organization is different from your GitHub organization. You can give your DevOps organization and your GitHub organization the same name if you want alignment between them.)

    If your team already has one, then make sure you're an administrator of the Azure DevOps project that you want to use.

  • An ability to run pipelines on Microsoft-hosted agents. You can either purchase a parallel job or you can request a free tier. To request a free tier, follow the instructions in this article. Please note that it may take us 2-3 business days to grant the free tier.

  • An Azure account. If you don't have one, you can create one for free.


    If you're new at this, the easiest way to get started is to use the same email address as the owner of both the Azure Pipelines organization and the Azure subscription.

Get the code

If you already have an app in GitHub that you want to deploy, you can create a pipeline for that code.

If you are a new user, fork this repo in GitHub:

Create an Azure Functions app

Sign in to the Azure Portal, and then select the Cloud Shell button in the upper-right corner.

Create an Azure App Service on Linux. Select the runtime you want to use.

# Create a resource group
az group create --location westus --name myapp-rg

# Create a storage account
az storage account create --name mystorage --location westeurope --resource-group myapp-rg --sku Standard_LRS

# Create an Azure Functions app
az functionapp create --resource-group myapp-rg --consumption-plan-location westeurope \
--name my-app-name --storage-account mystorage --runtime java

Update pom.xml

Update pom.xml to reflect your application. Edit the pom.xml file in your forked repository with your values for FUNCTION_APP_NAME, REGION, and RESOURCE_GROUP.


Sign in to Azure Pipelines and connect to Azure

Sign in to Azure Pipelines. After you sign in, your browser goes to and displays your Azure DevOps dashboard.

Within your selected organization, create a project. If you don't have any projects in your organization, you see a Create a project to get started screen. Otherwise, select the Create Project button in the upper-right corner of the dashboard.

Now create the service connection:

  1. From your project dashboard, select Project settings on the bottom left.

  2. On the settings page, select Pipelines > Service connections, select New service connection, and then select Azure Resource Manager.

  3. Select Service principal (automatic) and Next.

  4. The Add an Azure Resource Manager service connection dialog box appears.

    • Scope Select Subscription.
    • Subscription Select your Azure portal subscription.
    • Resource Group Select the resource group you created earlier.
    • Service connection name Type a name and then copy and paste it into a text file so you can use it later.
    • Select Grant access permission to all pipelines.

    New service connection dialog box


If you need to create a connection to an Azure subscription that's owned by someone else, see Create an Azure Resource Manager service connection with an existing service principal.

Create the pipeline

  1. Sign in to your Azure DevOps organization and navigate to your project.

  2. Go to Pipelines, and then select New Pipeline.

  3. Walk through the steps of the wizard by first selecting GitHub as the location of your source code.

  4. You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.

  5. When the list of repositories appears, select your repository.

  6. You might be redirected to GitHub to install the Azure Pipelines app. If so, select Approve & install.

When the Configure tab appears, select Maven. Your new pipeline appears.

  1. When prompted, select the Azure subscription in which you created your Web App.

  2. Select the Web App.

  3. Select Validate and configure.

    As Azure Pipelines creates an azure-pipelines.yml file, which defines your CI/CD pipeline, it:

    • Includes a Build stage, which builds your project, and a Deploy stage, which deploys it to Azure as a Linux web app.
    • As part of the Deploy stage, it also creates an Environment with default name same as the Web App. You can choose to modify the environment name.
  4. Take a look at the pipeline to see what it does. Make sure that all the default inputs are appropriate for your code.

  5. After you've looked at what the pipeline does, select Save and run, after which you're prompted for a commit message because Azure Pipelines adds the azure-pipelines.yml file to your repository. After editing the message, select Save and run again to see your pipeline in action.

You just created and ran a pipeline that we automatically created for because your code appeared to be a good match for the Maven Azure Pipelines template.

Edit the pipeline

After the pipeline has run, select the vertical ellipses in the upper-right corner of the window and then select Edit pipeline.

Set some variables for your deployment

# at the top of your YAML file 
# set some variables that you'll need when you deploy
  # the name of the service connection that you created above
  serviceConnectionToAzure: name-of-your-service-connection
  # the name of your web app here is the same one you used above
  # when you created the web app using the Azure CLI
  appName: my-app-name
  # the name of your functionApp is what you provided as
  # stagingDirectory in pom.xml
  functionAppName: 'javafunctions'
# ...

Deploy to Azure Functions

# ...
# add these as the last steps
# to deploy to your app service
- task: CopyFiles@2
  displayName: Copy Files
    SourceFolder: $(system.defaultworkingdirectory)/target/azure-functions/$(functionAppName)/
    Contents: '**'
    TargetFolder: $(build.artifactstagingdirectory)   

- task: PublishBuildArtifacts@1
  displayName: Publish Artifact
    PathtoPublish: $(build.artifactstagingdirectory)    

- task: AzureFunctionApp@1
  displayName: Azure Function App deploy
    azureSubscription: $(serviceConnectionToAzure)
    appType: functionApp
    appName: $(appName)
    package: $(build.artifactstagingdirectory)/$(appName)

Run the pipeline and check out your site

You're now ready to save your changes and try it out!

  1. Select Save in the upper-right corner of the editor.

  2. In the dialog box that appears, add a Commit message such as add deployment to our pipeline, and then select Save.

  3. In the pipeline editor, select Run.

When the Build #nnnnnnnn.n has been queued message appears, select the number link to see your pipeline in action.

After the pipeline has run, test the function app running on Azure. For example, in bash or from a command prompt enter:

curl -w '\n' -d fromYourPipeline

Your function then returns:

Hello PipelineCreator

Clean up resources

Whenever you're done with the resources you created above, you can use the following command to delete them:

az group delete --name myapp-rg

Type y when prompted.