skip to Main Content

I’ve been stuck for a while now on the issue I’m having where when I want to deploy my java app to Azure. It doesn’t recognise the artifact that I build in a previous workflow run. these are the build and deploy files:

name: Build JAR app - kobeodbCR-backend

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Java version
        uses: actions/setup-java@v1
        with:
          java-version: "17"

      - name: Build with Maven
        run: mvn clean install

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: java-app
          path: "${{ github.workspace }}/target/*.jar"
name: Deploy JAR app to Azure Web App - kobeodbCR-backend

on:
  workflow_run:
    workflows: ["Build JAR app - kobeodbCR-backend"]
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: java-app

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: "kobeodbCR-backend"
          slot-name: "Production"
          package: "*.jar"
          publish-profile: ${{ ... }}

and this is the error im getting:

deploy
Unable to download artifact(s): Artifact not found for name: java-app Please ensure that your artifact is not expired and the artifact was uploaded using a compatible version of toolkit/upload-artifact. For more information, visit the GitHub Artifacts FAQ: https://github.com/actions/toolkit/blob/main/packages/artifact/docs/faq.md

Why is this happening?

The build workflow completes successfully, and the artifact is created, but the deploy workflow fails after give or take 10 seconds.

I’ve tried a few different things, mostly recommendations from chatGPT, but none of them have successfully worked.

2

Answers


  1. There is no scope/context in the workflowB. You will need to to generate a token based on a github app that you need to add to your repo. Something like this:

    - name: Get GitHub App token
      id: get-token
      uses: actions/create-github-app-token@v1
      with:
        owner: 'me'
        app-id: ${{ secrets.APPLICATION_ID }}
        private-key: ${{ secrets.APPLICATION_PRIVATE_KEY }}
    
    - name: Download artifact from build job
      uses: actions/download-artifact@v4
      with:
        run-id: ${{ github.event.workflow_run.id }}
        github-token: ${{ github.token }}
        name: java-app
    

    To create the github app here is the doc: https://docs.github.com/es/apps/creating-github-apps/about-creating-github-apps/about-creating-github-apps

    An alternative much simplier would be to fuse both worklows and set an input parameter so you can decide when you upload or not the artefact. Example:

    name: Build JAR app - kobeodbCR-backend
    
    on:
     push:
     branches:
       - main
     workflow_dispatch:
       inputs:
         goToPRO:
         required: false
         type: string
         default: 'false'
         description: 'Should it go to PRO?'     
    
    jobs:
     build:
     runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v4
    
      - name: Set up Java version
        uses: actions/setup-java@v1
        with:
          java-version: "17"
    
      - name: Build with Maven
        run: mvn clean install
    
      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        if: ${{inputs.goToPRO == 'true'}}
        with:
          app-name: "kobeodbCR-backend"
          slot-name: "Production"
          package: "*.jar"
          publish-profile: ${{ ... }}
    
    Login or Signup to reply.
  2. you need to specify run id in the download-artifact step to accomplish this as these workflows running independently

    - name: Download Artifacts 
      uses: actions/download-artifact@v4
      with:
        name: java-app
        run-id: ${{ github.event.workflow_run.id }}
        github-token: ${{ secrets.GITHUB_TOKEN }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search