Gurobi License Management

Some of the MILP algorithms may require or optionally include Gurobi as solver. To use Gurobi, you need to have a valid license. You can obtain a free academic license if you are a student or a researcher at an academic institution. For commercial use, you will need to purchase a license from Gurobi.

Gurobi on Local Machine

To use Gurobi on your local machine, you need to follow the instructions provided by Gurobi:

Gurobi WLS License on CI-Server

To enable your CI pipeline to access the Gurobi solver using your WLS academic license, you need to securely provide the license information to your CI-Pipeline. Here’s a step-by-step guide:

1. Obtain Your Gurobi WLS Academic License

  • Register or log in to your account at Gurobi User Portal.
  • Go to Request and under WLS Academic click on Generate NOW!.
  • Download your Gurobi WLS license file (usually named gurobi.lic).
  • The Gurobi WLS license is valid for 90 days, but can easily be renewed in the Gurobi Web License Manager, just click on Extend next to the expiration date of your license.
  • Security Considerations:
    • Never commit your license file directly to your repository.
    • Use GitHub Secrets, GitLab Variables, etc. to keep your license information secure.
    • Restrict access to your repository to trusted collaborators.

GitLab

2. Add the License Information as a GitLab CI/CD Variables

  • Go to your GitLab projectSettingsCI/CD > Variables.
  • In Section Project variables > CI/CD Variables click Add variable.
  • Create Variable:
    • Key: GRB_LICENSEID
    • Value: LICENSEID from the gurobi.lic
    • uncheck Flag Protected variable
    • set Visibility to Visible (in case there is an error, since the value is too short)
  • Create Variable:
    • Key: GRB_WLSACCESSID
    • Value: WLSACCESSID from the gurobi.lic
    • uncheck Flag Protected variable
  • Create Variable:
    • Key: GRB_WLSSECRET
    • Value: WLSSECRET from the gurobi.lic
    • uncheck Flag Protected variable

3. Configure Your GitLab Workflow

In your workflow YAML file (e.g., .gitlab-ci.yml), you need to:

  • Set up the environment to use the Gurobi license.
  • Ensure the license file is written to the correct location before running your tests.
  • The GRB_LICENSE_FILE environment variable must point to the location of your gurobi.lic file.
  • Ensure this variable is set before any step that requires the Gurobi solver.

Example GitLab-CI Snippet:

Here’s an example of how to set up the Gurobi license in a GitLab-CI workflow:

unit-test-job:
  stage: test

  before_script:
    - echo "Setting up Gurobi WLS license..."
    - echo "WLSACCESSID=$GRB_WLSACCESSID" > gurobi.lic
    - echo "WLSSECRET=$GRB_WLSSECRET" >> gurobi.lic
    - echo "LICENSEID=$GRB_LICENSEID" >> gurobi.lic
    - export GRB_LICENSE_FILE=$(pwd)/gurobi.lic
    - echo "Gurobi license file set up at" $GRB_LICENSE_FILE
  script:
    - echo "Running unit tests..."
    - ...

GitHub

2. Add the License File as a GitHub Secret

  • Go to your GitHub Organization or GitHub repositorySettingsSecrets and variablesActions. → Direct Link
  • Click Organization secret or New repository secret.
  • Name the secret (e.g., GUROBI_LICENSE) and paste the entire content of your gurobi.lic file as the value.
  • Save the secret.

3. Configure Your GitHub Actions Workflow

In your workflow YAML file (e.g., .github/workflows/ci.yml), you need to:

  • Set up the environment to use the Gurobi license.
  • Ensure the license file is written to the correct location before running your tests.
  • The GRB_LICENSE_FILE environment variable must point to the location of your gurobi.lic file. In the example above, it is set to ~/gurobi_license/gurobi.lic.
  • Ensure this variable is set before any step that requires the Gurobi solver.

Example GitHub Actions Snippet:

Here’s an example of how to set up the Gurobi license in a GitHub Actions workflow:

jobs:
  test:
    steps:
      - name: Set Gurobi License
        if: ${{ !env.ACT }} # skip a step that you don't want to run locally with "nektos/act"
        run: |
          # Create a license file from the secret
          echo "${{ secrets.GUROBI_LICENSE }}" > gurobi.lic
          export GRB_LICENSE_FILE="${{ github.workspace }}/gurobi.lic"
        shell: bash