Back to Blog
Lesson 4 of the CI/CD: Continuous Integration from Scratch course
DevOpsJuly 4, 20264 min read

Hello World Pipeline: Your First GitHub Actions Automation

Learn to build your first GitHub Actions pipeline. We’ll guide you through writing a "Hello World" workflow and verifying its execution in the runner.

GitHub ActionsCI/CDAutomationDevOpsYAMLTutorials

Previously in this course, we explored the CI/CD Philosophy: Automating Your Software Delivery and ensured your environment was set up correctly. In the last lesson, we covered the Anatomy of a Workflow: Mastering GitHub Actions YAML Structure, which defined the rules for how our automation files should look.

Now, it’s time to move from theory to action. In this lesson, we will write a functional workflow that prints "Hello World" to the console. This simple task is the "rite of passage" for every DevOps engineer, confirming that your connection to the GitHub Actions infrastructure is healthy and your runner environment is ready to execute code.

Understanding the Runner Environment

When you trigger a workflow, GitHub doesn't run your code on its main website servers. Instead, it spins up a virtual machine—a runner—specifically for your task.

Think of the runner as a clean, temporary workspace. When the workflow starts, the runner is provisioned, your code is checked out, your commands are executed, and then the environment is discarded. By writing a "Hello World" script, you are testing that this ephemeral machine can successfully interpret your instructions.

Creating Your First Workflow

We will create a workflow file that triggers on a manual click (using the workflow_dispatch event). This allows you to test your pipeline without needing to push code changes every time you want to see a result.

Navigate to your local repository and ensure the directory structure exists:

Bash
mkdir -p .github/workflows

Create a new file named .github/workflows/hello-world.yml and add the following content:

YAML
name: Hello World Pipeline

on:
  workflow_dispatch:

jobs:
  say-hello:
    runs-on: ubuntu-latest
    steps:
      - name: Print greeting
        run: echo "Hello World! The automation is working."

Breaking Down the Code

  • name: The label that appears in your GitHub Actions tab.
  • on: workflow_dispatch: This creates a "Run workflow" button in the GitHub UI.
  • runs-on: ubuntu-latest: This tells GitHub to provision a fresh, standard Linux environment.
  • run: This is where the magic happens. It executes standard shell commands just as if you were typing them into your own terminal.

Verifying Execution in the GitHub UI

Once you have saved the file, commit and push it to your repository:

  1. git add .github/workflows/hello-world.yml
  2. git commit -m "Add hello world workflow"
  3. git push origin main

Now, head over to your repository on GitHub.com:

  1. Click on the Actions tab.
  2. On the left-hand sidebar, you will see "Hello World Pipeline". Click it.
  3. You will see a banner saying "This workflow has a workflow_dispatch trigger." Click the Run workflow button on the right, then click the green Run workflow button that appears.
  4. Refresh the page. You will see a new entry in the list. Click on it to watch the logs as the runner executes your echo command.

Hands-on Exercise

To confirm you have mastered the basics, try these two modifications:

  1. Add a second step: Create a new step in your YAML file that prints a different message, such as "Checking the date: " followed by the command date.
  2. Observe the Logs: Push these changes, trigger the workflow again, and look at the logs to see both messages appearing in the correct order.

Common Pitfalls

  • YAML Indentation: GitHub Actions is extremely strict about spaces. Ensure you are using two spaces for indentation—never tabs. If the file doesn't appear in the Actions tab, check for invalid syntax.
  • Wrong File Path: Your workflow must be inside .github/workflows/. Files placed directly in .github/ or elsewhere will be ignored.
  • Runner Latency: Sometimes, it takes a few seconds for the runner to provision. If the job stays in a "queued" state, wait 10–20 seconds; it is perfectly normal.

FAQ

Q: Do I always have to use ubuntu-latest? A: No, you can also use windows-latest or macos-latest, but ubuntu-latest is the standard for most CI/CD tasks due to its speed and low cost.

Q: Where can I see the environment details? A: If you expand the log steps in the GitHub UI, you can see the environment variables and the specific machine details the runner provides.

Q: What if my workflow doesn't show up in the Actions tab? A: Ensure your YAML file is committed to the default branch (usually main or master). If you are working on a feature branch, the UI will only show the workflow if you navigate to the "Actions" tab while that branch is active.

Recap

In this lesson, we successfully bridged the gap between your local terminal and the cloud. By creating a GitHub Actions workflow, we verified that your runner environment can execute code, setting the stage for more complex automation tasks.

Up next: We will dive deeper into Understanding Runners and Jobs to learn how to manage multi-step workflows and analyze logs like a pro.

Similar Posts