Note: GitHub Actions was available for GitHub Enterprise Server 2.22 as a limited beta. The beta has ended. GitHub Actions is now generally available in GitHub Enterprise Server 3.0 or later. For more information, see the GitHub Enterprise Server 3.0 release notes.
- For more information about upgrading to GitHub Enterprise Server 3.0 or later, see "Upgrading GitHub Enterprise Server."
- For more information about configuring GitHub Actions after you upgrade, see the documentation for GitHub Enterprise Server 3.0.
Note: GitHub-hosted runners are not currently supported on GitHub Enterprise Server. You can see more information about planned future support on the GitHub public roadmap.
Informationen zu Umgebungsvariablen
GitHub setzt Standard-Umgebungsvariablen, die für jeden Schritt in einem Workflow-Lauf verfügbar sind. Bei Umgebungsvariablen wird die Groß-/Kleinschreibung berücksichtigt. Befehle, die in Aktionen oder „Steps“ (Schritten) ausgeführt werden, können Umgebungsvariablen erstellen, lesen und ändern.
Um benutzerdefinierte Umgebungsvariablen festzulegen, musst Du die Variablen in der Workflow-Datei angeben. You can define environment variables for a step, job, or entire workflow using the jobs.<job_id>.steps[*].env
, jobs.<job_id>.env
, and env
keywords. Weitere Informationen finden Sie unter „Workflow-Syntax für GitHub“.
jobs:
weekday_job:
runs-on: ubuntu-latest
env:
DAY_OF_WEEK: Mon
steps:
- name: "Hello world when it's Monday"
if: ${{ env.DAY_OF_WEEK == 'Mon' }}
run: echo "Hello $FIRST_NAME $middle_name $Last_Name, today is Monday!"
env:
FIRST_NAME: Mona
middle_name: The
Last_Name: Octocat
To use the value of an environment variable in a workflow file, you should use the env
context. If you want to use the value of an environment variable inside a runner, you can use the runner operating system's normal method for reading environment variables.
If you use the workflow file's run
key to read environment variables from within the runner operating system (as shown in the example above), the variable is substituted in the runner operating system after the job is sent to the runner. For other parts of a workflow file, you must use the env
context to read environment variables; this is because workflow keys (such as if
) require the variable to be substituted during workflow processing before it is sent to the runner.
You can also use the set-env
workflow command to set an environment variable that the following steps in a job can use. The set-env
command can be used directly by an action or as a shell command in a workflow file using the run
keyword. Weitere Informationen findest Du unter „Workflow-Befehle für GitHub Actions“.
Standard-Umgebungsvariablen
Es wird dringend empfohlen, dass Aktionen Umgebungsvariablen verwenden, um auf das Dateisystem zuzugreifen, anstatt hartcodierte Dateipfade zu verwenden. GitHub legt Umgebungsvariablen für Aktionen fest, die in allen Runner-Umgebungen verwendet werden sollen.
Umgebungsvariable | Beschreibung |
---|---|
CI | Immer auf true gesetzt. |
GITHUB_WORKFLOW | Der Name des Workflows. |
GITHUB_RUN_ID | Eine eindeutige Nummer für jede Ausführung innerhalb eines Repository. Diese Nummer ändert sich nicht, wenn Du den Workflowablauf erneut ausführst. |
GITHUB_RUN_NUMBER | Eine eindeutige Nummer für jede Ausführung eines bestimmten Workflows in einem Repository. Diese Nummer beginnt bei 1 für die erste Ausführung des Workflows und erhöht sich mit jeder neuen Ausführung. Diese Nummer ändert sich nicht, wenn Du den Workflowablauf erneut ausführst. |
GITHUB_JOB | The job_id of the current job. |
GITHUB_ACTION | Die eindeutige Kennung (id ) der Aktion. |
GITHUB_ACTION_PATH | The path where your action is located. You can use this path to access files located in the same repository as your action. This variable is only supported in composite actions. |
GITHUB_ACTIONS | Immer auf true gesetzt, wenn GitHub Actions den Workflow ausführt. Du kannst diese Variable verwenden, um zu differenzieren, wann Tests lokal oder von GitHub Actions durchgeführt werden. |
GITHUB_ACTOR | Name der Person oder App, die den Workflow initiiert hat. Beispiel: octocat . |
GITHUB_REPOSITORY | Der Inhaber- und Repository-Name, Beispiel: octocat/Hello-World . |
GITHUB_EVENT_NAME | Name des Webhook-Ereignisses, das den Workflow ausgelöst hat. |
GITHUB_EVENT_PATH | Pfad der Datei mit der gesamten Nutzlast des Webhook-Ereignisses. Beispiel: /github/workflow/event.json . |
GITHUB_WORKSPACE | The GitHub workspace directory path, initially empty. Beispiel: /home/runner/work/my-repo-name/my-repo-name . The actions/checkout action will check out files, by default a copy of your repository, within this directory. |
GITHUB_SHA | Commit-SHA, die den Workflow ausgelöst hat. Beispiel: ffac537e6cbbf934b08745a378932722df287a53 . |
GITHUB_REF | Branch- oder Tag-Ref, das den Workflow ausgelöst hat. Beispiel: refs/heads/feature-branch-1 . Wenn für den Ereignistyp weder ein Branch noch ein Tag vorliegt, ist die Variable nicht vorhanden. |
GITHUB_HEAD_REF | Only set for pull request events. The name of the head branch. |
GITHUB_BASE_REF | Only set for pull request events. The name of the base branch. |
GITHUB_SERVER_URL | Returns the URL of the GitHub Enterprise Server server. For example: https://[hostname] . |
GITHUB_API_URL | Gibt die API-URL zurück. For example: http(s)://[hostname]/api/v3 . |
GITHUB_GRAPHQL_URL | Gibt die GraphQL-API-URL zurück. For example: http(s)://[hostname]/api/graphql . |
RUNNER_NAME | The name of the runner executing the job. |
RUNNER_OS | Das Betriebssystem des Runners, der den Job ausführt. Mögliche Werte sind Linux , Windows oder macOS . |
RUNNER_TEMP | The path to a temporary directory on the runner. This directory is emptied at the beginning and end of each job. Note that files will not be removed if the runner's user account does not have permission to delete them. |
RUNNER_TOOL_CACHE | The path to the directory containing preinstalled tools for GitHub-hosted runners. For more information, see "Specifications for GitHub-hosted runners". |
Note: If you need to use a workflow run's URL from within a job, you can combine these environment variables: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
Determining when to use default environment variables or contexts
GitHub Actions includes a collection of variables called contexts and a similar collection of variables called default environment variables. These variables are intended for use at different points in the workflow:
- Default environment variables: These variables exist only on the runner that is executing your job. For more information, see "Default environment variables."
- Contexts: You can use most contexts at any point in your workflow, including when default environment variables would be unavailable. For example, you can use contexts with expressions to perform initial processing before the job is routed to a runner for execution; this allows you to use a context with the conditional
if
keyword to determine whether a step should run. Once the job is running, you can also retrieve context variables from the runner that is executing the job, such asrunner.os
. For details of where you can use various contexts within a workflow, see "Context availability."
The following example demonstrates how these different types of environment variables can be used together in a job:
name: CI
on: push
jobs:
prod-check:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- run: echo "Deploying to production server on branch $GITHUB_REF"
In this example, the if
statement checks the github.ref
context to determine the current branch name; if the name is refs/heads/main
, then the subsequent steps are executed. The if
check is processed by GitHub Actions, and the job is only sent to the runner if the result is true
. Once the job is sent to the runner, the step is executed and refers to the $GITHUB_REF
environment variable from the runner.
Namens-Konventionen für Umgebungsvariablen
When you set a custom environment variable, you cannot use any of the default environment variable names listed above with the prefix GITHUB_
. If you attempt to override the value of one of these default environment variables, the assignment is ignored.
Alle neuen Umgebungsvariablen, die auf einen Speicherort im Dateisystem verweisen, müssen das Suffix _PATH
erhalten. Die Standardvariablen HOME
und GITHUB_WORKSPACE
sind von dieser Konvention ausgenommen, da die Bezeichnungen „home“ und „workspace“ bereits einen Speicherort implizieren.