Triggering with Git Operations

For Regular Users

This guide provides Git command examples for triggering PAC pipelines through Git operations.

This guide shows common Git commands used to trigger PAC pipelines through Git provider events.

How PAC Triggers Work

PAC uses webhooks from Git providers (GitHub, GitLab, Bitbucket, etc.) to detect events:

  1. Webhook Configuration: When you create a Repository CR, PAC automatically configures a webhook in your Git provider
  2. Event Detection: When events occur (push, pull request, comments), the Git provider sends a webhook to PAC controller
  3. Pipeline Matching: PAC controller matches the event against annotations in your PipelineRun files
  4. Pipeline Execution: If a match is found, PAC creates a PipelineRun in your cluster

For more details on pipeline definitions and event annotations, see Maintain Pipeline Code.

TOC

Testing Push Triggers

Basic Push

Make a change and push to trigger pipelines:

echo "test" >> test.txt
git add test.txt
git commit -m "Test push trigger"
git push origin main

Push to Specific Branch

Create and push to a feature branch:

git checkout -b feature/new-feature
echo "feature code" >> feature.txt
git add feature.txt
git commit -m "Add new feature"
git push origin feature/new-feature

Empty Commit

Trigger pipeline without code changes:

git commit --allow-empty -m "Trigger pipeline"
git push origin main

Testing Merge Request Triggers

Create Merge Request

  1. Create a feature branch:

    git checkout -b feature/test-mr
    echo "feature" >> feature.txt
    git add feature.txt
    git commit -m "Add feature for MR test"
    git push origin feature/test-mr
  2. Create a Pull/Merge Request targeting main branch via your Git provider UI

Update Merge Request

Push more commits to trigger pipeline again:

echo "update" >> feature.txt
git add feature.txt
git commit -m "Update feature"
git push origin feature/test-mr

Force Push to Merge Request

Rewrite history and force push:

git commit --amend --no-edit
git push --force-with-lease origin feature/test-mr

Note: Use --force-with-lease instead of --force to prevent overwriting others' work.

Using Comment Commands

Comment commands only work in Merge Requests (Pull Requests), not in regular commits or push events.

Trigger via Comment

  1. Open your Pull/Merge Request in the Git provider UI

  2. Add a comment with the command:

    /retest

or

/test
  1. PAC will detect the comment and trigger the corresponding pipeline

Common Comment Commands

CommandDescription
/retestRe-run all failed tests
/testRun tests
/ok-to-testApprove running tests (if required)
/cancelCancel running pipeline

Note: The exact commands depend on your pipeline configuration. You define commands in the on-comment annotation in your PipelineRun files.

Checking Pipeline Status

View PipelineRuns

Check if pipeline was triggered:

kubectl get pipelineruns -n <namespace>

View Pipeline Logs

View logs of a specific PipelineRun:

tkn pipelinerun logs <pipelinerun-name> -n <namespace>

Or follow logs in real-time:

tkn pipelinerun logs <pipelinerun-name> -n <namespace> -f

Check Latest PipelineRun

Get the latest PipelineRun:

kubectl get pipelineruns -n <namespace> --sort-by=.metadata.creationTimestamp | tail -1

Troubleshooting Git Operations

Check Current Branch

Verify you're on the correct branch:

git branch --show-current

Verify Last Commit

Check the last commit details:

git log --oneline -1

Check Remote Branch

Verify branch exists on remote:

git branch -r | grep <branch-name>

View Git Remote

Check configured remote URL:

git remote -v

Force Sync with Remote

Reset local branch to match remote:

git fetch origin
git reset --hard origin/<branch-name>

Warning: This will discard local changes.

Next Steps