How to add two numbers

Hello, how do I add a number to the GITHUB_RUN_NUMBER, this does not work:

env:
      GITHUB_RUN_NUMBER_WITH_OFFSET: ${{ github.run_number + 200 }}

Unexpected symbol: '+'. Located at position 19 within expression: github.run_number + 200

Is it even possible to do a little computation like this? I’ve spent far too long trying to figure this out :slight_smile:

1 Like

@danielwilson1702 

Github actions doesn’t support math operations in expressions inside ${{  }}. You could add up these two numbers in bash script and then use set-env command to give its value to an environment variable, please try my example: 

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: run number with offset
      env:
          NUM: ${{ github.run_number }}
      run: |
          echo ::set-env name=GITHUB_RUN_NUMBER_WITH_OFFSET::$(($NUM+200))
    - run: echo $GITHUB_RUN_NUMBER_WITH_OFFSET
1 Like

Thank you, that works well!

Hi, I tried a similar approach but it doesn’t seem to be working. Any ideas?

  - name: My Code
      env:
          OLDNUM: ${{ steps.my-step.outputs.mynum }}
      run: |
        echo "Current Number is $OLDNUM"
        echo ::set-env name=NEWNUM::$(($OLDNUM+1))
        echo "New Number is $NEWNUM"

It gets the output “mynum” correctly, I see it in the echo. But it doesn’t perform the operation of adding 1 to it or setting the new env var. I get an empty variable. Any ideas?

thanks

An environment variable set using ::set-env is not available within the same step, only the following ones (see documentation). If you want to use it in the same step you should be able to use normal Bash variable assignment.

This is an expected behavior.

::set-env name={name}::{value}

This command creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access.
https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable