Skip to main content

Different Job Secret for Different Branch

Define multiple secrets with the same name to select a value according to job authorization. OneDev uses the first authorized secret with that name, searching the current project before its parents.

Configure the Secrets​

Open the project's Settings > Build > Job Secrets.

  1. Add a secret named deployment with the production value and authorization on branch "main".
  2. After it, add another secret also named deployment with the development value and authorization on branch "**".
  3. Keep the main-branch entry first. Reference @secret:deployment@ in the job wherever the selected value is needed.

Ordered secrets and their authorizations

The default branch authorization is on branch "**"; leaving authorization completely empty is different, as it also permits jobs triggered through external pull requests. Choose the authorization appropriate for your workflow.

Verify Selection​

Use disposable test values first. Run the job on a commit reachable from main, then on a feature-branch commit that has not been merged into main. The first run should receive the main entry; the second should receive the fallback entry. Check the value with a command that reports only whether the expected value matched, rather than printing a real secret.

Authorization considers whether the build commit is reachable from the named branch. A commit already merged into main can therefore use the main-branch secret even when another branch also points to it.