Perform next job, if specific step of previous job was success

I have a single workflow file setup, which performs two separate jobs right now:

  • Building and then uploading specific files

  • Post a release message on a Discord about it.

Now I want to add an additional 2 steps to the first job to zip the generated files after the upload and then attach them to the release itself.

The problem now is, that the second job depends on the first one and only runs when the previous step was a success (Using “if: success()”)

Now with the extra two steps added would it not be guaranteed anymore that it would be a success, as the last step is no longer the upload, but the attachment of the zip to the release, which may or may not fail.

I only want the next job to run, if the step “publish_bintray” was a success.

My workflow file is like this now:

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Publish (Bintray)
      id: publish_bintray
      env:
        bintrayUser: ${{ secrets.bintrayUsername }}
        bintrayApiKey: ${{ secrets.bintrayApiKey }}
      run: ./gradlew bintrayUpload # Starts a task to build and then upload the files
#
# The below two actions would now be a problem for "success()" in next job
    - name: Zip files
      run: |
        cd build # The build files are in a /build directory
        zip release-${{ github.event.release.tag_name }} *.jar
    - name: Upload to release
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ github.event.release.release.upload_url }}
        asset_path: ./build/release-${{ github.event.release.tag_name }}.zip
        asset_name: release-${{ github.event.release.tag_name }}.zip
        asset_content_type: application/zip
  sendMessage:
    needs: [publish]
    if: success()
    runs-on: ubuntu-latest
    steps:
    - name: Discord notification
      uses: rjstone/discord-webhook-notify@v1
      with:
        webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
        severity: info
        avatarUrl: 'https://raw.githubusercontent.com/botblock/JavaBotBlockAPI/master/src/main/resources/jbba.png'
        username: 'New release (${{ github.event.release.tag_name }})'
        text: '${{ github.event.release.name }}'
        description: '[**Release Information**](${{ github.event.release.html_url }})'
        details: '${{ github.event.release.body }}'
        footer: 'Version ${{github.event.release.tag_name}}'

The information about the if-option is extremely spare in terms of proper usage with steps from other jobs and the success() option is fairly limited in terms of customization/advanced usage,

I have workaround here maybe you can consider it as a reference:

you can add 2 extra steps following the step “Publish (Bintray)”, the first one is used to create a text file and write the content ‘ true ’ in it, and the second one is used to upload this text file as an artifact.

In job “ send_message ”, also add 2 extra steps as the top, the first one is used to download the artifact, the second one is used to read the content of the text file from the downloaded artifact, and set the content as the value of a output parameter.

Then according to the output parameter value to decide whether execute step “ Discord notification ”.

A simple demo:

jobs:
  publish:
  . . .
    steps:
      - name: Publish (Bintray)
        . . .
      - name: Create file post_message.txt and write 'true' into it
        run: echo 'true' > post_message.txt

      - name: Upload file post_message.txt
        uses: actions/upload-artifact@v1
        with:
          name: pass_file
          path: post_message.txt

      - name: Zip files
        . . .
      - name: Upload to release
        . . .
  send_message:
    needs: [publish]
    if: always()
        . . .
    steps:
      - name: Download file post_message.txt
        uses: actions/download-artifact@v1
        with:
          name: pass_file

      - name: Read file post_message.txt and set output parameter
        id: set_output
        run: echo "::set-output name=post_message::$(<pass_file/post_message.txt)"

      - name: Discord notification
        if: steps.set_output.outputs.post_message == 'true'
        . . .

Note: Because the value of output parameter only can be shared between the steps in a same job, and can’t be shared across jobs, so I select using artifact to pass the value across jobs.