WorkingDirectory icon
Clone icon
Commands icon
Docker icon

Clone a GitHub repository and run a Shell script

Clone a GitHub repository and run its shell scripts in Docker with Kestra. Keep automation version-controlled, reproducible, and orchestrated end to end.

Categories
Infrastructure
id: git-scripts
namespace: company.team

tasks:
  - id: scripts
    type: io.kestra.plugin.core.flow.WorkingDirectory
    tasks:
      - id: clone_repository
        type: io.kestra.plugin.git.Clone
        url: https://github.com/kestra-io/scripts
        branch: main
      - id: run_script
        type: io.kestra.plugin.scripts.shell.Commands
        taskRunner:
          type: io.kestra.plugin.scripts.runner.docker.Docker
        commands:
          - cd shell
          - chmod +x hello_world.sh
          - ./hello_world.sh

Run shell scripts straight from a Git repository instead of pasting them into a scheduler. This blueprint clones a GitHub repo, then executes a versioned shell script inside an isolated Docker container, so your automation logic stays in source control, code-reviewed and reproducible. It is the GitOps pattern for operational scripting: the repository is the single source of truth, and Kestra is the engine that runs it on demand or on a schedule.

How it works

  1. A io.kestra.plugin.core.flow.WorkingDirectory task (scripts) opens a shared working directory so the clone and the script run share the same filesystem.
  2. The io.kestra.plugin.git.Clone task (clone_repository) clones https://github.com/kestra-io/scripts at the main branch into that directory.
  3. The io.kestra.plugin.scripts.shell.Commands task (run_script) runs on the io.kestra.plugin.scripts.runner.docker.Docker task runner: it changes into the shell folder, makes hello_world.sh executable with chmod +x, and executes it.

What you get

  • Version-controlled automation: scripts live in Git, not in a UI text box.
  • Reproducible execution in a clean Docker container every run.
  • A working directory that wires clone output directly into the script step.
  • A pattern that scales from one script to an entire repository of tooling.

Who it's for

  • DevOps and platform engineers running operational and maintenance scripts.
  • Data engineers who keep ingestion or cleanup logic in shell.
  • Teams adopting GitOps who want every script execution traceable to a commit.

Why orchestrate this with Kestra

Git has no scheduler and no execution engine: it stores your scripts but never runs them. Cron on a server runs scripts but loses version history, retries, and observability. Kestra closes that gap. Declarative YAML defines the clone and run steps, event triggers and schedules fire executions automatically, per-task retries and timeouts handle flaky steps, and every run is captured with logs and lineage so you can see exactly which commit produced which result.

Prerequisites

  • A Kestra instance with the Git and Scripts plugins (bundled by default).
  • Docker available to the worker for the Docker task runner.

Secrets

This blueprint clones a public repository, so no secrets are required. For private repositories, add username and password (or a token) to the clone_repository task and store them with {{ secret('GIT_USERNAME') }} and {{ secret('GIT_PASSWORD') }}.

Quick start

  1. Add this flow in the Kestra UI.
  2. Confirm Docker is reachable from the worker.
  3. Execute the flow and watch clone_repository then run_script in the logs.
  4. Inspect the script output and exit code in the execution view.

How to extend

  • Point url and branch at your own repository and script path.
  • Swap hello_world.sh for any script, or chain multiple Commands steps.
  • Add a Schedule or webhook trigger to run on a cadence or on push.
  • Add username/password to clone private repositories.
  • Pass flow inputs into the script as arguments or environment variables.

Links

Orchestrate with Kestra
Orchestrate Git with Kestra
Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.