Configure GitLab Repository
This guide is for regular users to configure their GitLab repositories for PAC integration. If you need information about PAC controller URL or webhook configuration, see the query instructions below.
Important: Throughout this document, we use two different namespaces:
<pac-namespace>: The namespace where PAC components (controller, watcher, webhook) are deployed. Default istekton-pipelines, but can be customized viatargetNamespacein theOpenShiftPipelinesAsCodeCR.<your-namespace>or Pipeline namespace: The namespace where PipelineRuns are created. This is specified when creating the Repository CR and can be any namespace in your cluster.
Replace these placeholders with your actual namespace names.
This guide explains how to configure a GitLab repository to work with PAC, enabling pipelines to be triggered from GitLab events.
TOC
PrerequisitesOverviewStep 1: Install tkn pac PluginStep 2: Prepare GitLab Access TokenCreate Personal Access TokenStore Token SecurelyStep 3: Get PAC Controller URLMethod 1: Query Ingress (if configured)Method 2: Query NodePort Service (if configured)Method 3: Query LoadBalancer Service (if configured)Automatic Detection by tkn pacIf You Cannot Find the URLStep 4: Configure Repository with tkn pacNavigate to Your RepositoryRun tkn pac create repoInteractive Configuration1. Git Repository URL2. Namespace for Pipelines3. GitLab Project ID4. PAC Controller URL5. Webhook Secret6. GitLab Access Token7. GitLab API URLExample Interactive SessionStep 5: Verify ConfigurationCheck Repository CRCheck GitLab WebhookCheck Kubernetes SecretCheck Generated TemplateStep 6: Test the ConfigurationTest Webhook ConnectionTrigger a Test PipelineManual Configuration (Alternative)Create Repository CR ManuallyCreate GitLab SecretCreate Webhook SecretConfigure GitLab Webhook ManuallyUsing Private RepositoriesInterfacing with Custom CertificatesTroubleshootingCheck if Repository CR is Not CreatedCheck if Webhook is Not ConfiguredCheck if Webhook Events are Not ReceivedCheck if PipelineRuns are Not CreatedCheck if Private Repository Access IssuesCheck if Certificate IssuesNext StepsPrerequisites
Before configuring a GitLab repository, ensure you have:
- PAC component deployed and running (see Manage PAC Component)
- PAC controller exposed and accessible (via Ingress or NodePort)
tknCLI installed withpacplugin- GitLab repository with repo-scope admin access
- GitLab Personal Access Token with appropriate scopes
Overview
The tkn pac create repo command is the recommended way to configure a GitLab repository for PAC. It automates the entire setup process:
- Creates a Repository CR in your Kubernetes cluster
- Configures GitLab webhook automatically
- Creates Kubernetes Secret with GitLab credentials
- Generates a basic
.tekton/pipelinerun.yamltemplate in your repository
Step 1: Install tkn pac Plugin
Ensure you have the tkn pac plugin installed:
If not installed, follow the installation guide in tkn pac Command Reference.
Step 2: Prepare GitLab Access Token
You need a GitLab Personal Access Token with the following scopes:
api: Full API access
Create Personal Access Token
- Go to GitLab → User Settings → Access Tokens (or Project Settings → Access Tokens for project tokens)
- Create a new token with:
- Name:
PAC Integration(or any descriptive name) - Scopes: Select
api - Expiration date: Set as needed (optional)
- Name:
- Click Create personal access token
- Copy the token immediately - it won't be shown again
Store Token Securely
Save the token in a secure location. You'll need it when running tkn pac create repo.
Security Best Practice: Consider using a project token instead of a personal token for better access control.
Step 3: Get PAC Controller URL
Before configuring the repository, you need the PAC controller URL. This URL is used by GitLab to send webhook events to PAC.
If you don't know the PAC controller URL, try the following commands to query it. If these commands don't return a result, contact your PAC administrator.
Method 1: Query Ingress (if configured)
Check if PAC controller is exposed via Ingress (replace <pac-namespace> with your PAC namespace, default is tekton-pipelines):
Example output (if Ingress is configured):
If found, get the Ingress host:
Example output:
The controller URL will be:
- HTTP:
http://<ingress-host> - HTTPS:
https://<ingress-host>
Method 2: Query NodePort Service (if configured)
Check if PAC controller is exposed via NodePort (replace <pac-namespace> with your PAC namespace, default is tekton-pipelines):
Example output (if NodePort is configured):
If found, get the NodePort and node IP:
Example output:
Method 3: Query LoadBalancer Service (if configured)
Check if PAC controller is exposed via LoadBalancer (replace <pac-namespace> with your PAC namespace, default is tekton-pipelines):
Example output (if LoadBalancer is configured):
If found, get the service name and external IP:
Example output:
Automatic Detection by tkn pac
The tkn pac create repo command can automatically detect the controller URL by checking:
- Ingress resources
- LoadBalancer services
- NodePort services
If automatic detection fails, you can manually enter the URL when prompted.
If You Cannot Find the URL
If none of the above methods work or you don't have permission to query cluster resources:
- Contact your PAC administrator to get the PAC controller URL
- The administrator can find it using the methods in Manage PAC Component
- The URL format is typically:
http://<host-or-ip>:<port>orhttps://<host-or-ip>
Step 4: Configure Repository with tkn pac
Navigate to Your Repository
Clone or navigate to your GitLab repository:
Run tkn pac create repo
Important: Navigate to your GitLab repository directory before running the command. The .tekton directory will be created in the current working directory.
Note: If PAC is installed in a different namespace, adjust the --pac-namespace parameter accordingly. Replace tekton-pipelines with your actual PAC namespace if you deployed PAC in a different namespace. The --pac-namespace parameter specifies where the PAC controller is deployed (default: tekton-pipelines).
Interactive Configuration
The command will prompt you for the following information:
1. Git Repository URL
- Default: Auto-detected from current directory's git remote
- Format:
https://gitlab.com/username/repoorgit@gitlab.com:username/repo - Action: Press Enter to use default, or enter a different URL
2. Namespace for Pipelines
- Default:
default - Description: Kubernetes namespace where PipelineRuns will be created
- Action: Enter your preferred namespace (e.g.,
project-pipelines), or press Enter to usedefault
Important:
-
The namespace must exist before PAC can create PipelineRuns in it
-
If the namespace doesn't exist, create it first:
Example:
-
It's recommended to use a dedicated namespace like
project-pipelinesinstead ofdefault -
The namespace must have RBAC permissions for PAC to create resources
3. GitLab Project ID
- How to find:
- Go to your GitLab project → Settings → General
- Find "Project ID" under "Project information"
- Or use the API:
curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects?search=<repo-name>"
4. PAC Controller URL
- Default: Auto-detected from cluster resources
- Action:
- If auto-detected correctly, press Enter
- If not detected, enter the URL manually
- If you don't know the URL: See Step 3: Get PAC Controller URL above for query commands, or contact your PAC administrator
5. Webhook Secret
- Default: Auto-generated random string
- Description: Secret used to validate webhook requests from GitLab
- Action: Press Enter to use default, or enter a custom secret
Security: Keep this secret secure. It's stored in the Kubernetes Secret.
6. GitLab Access Token
- Description: The Personal Access Token created in Step 2
- Action: Paste your token
7. GitLab API URL
- Default:
https://gitlab.com(for GitLab.com) - For self-hosted GitLab: Enter your GitLab instance URL, e.g.,
https://gitlab.example.com - Action: Press Enter for GitLab.com, or enter your instance URL
Example Interactive Session
Step 5: Verify Configuration
Check Repository CR
First, determine your namespace (the namespace you specified when creating the Repository CR). If you don't remember, list all Repository CRs:
Example output:
Then verify the Repository CR was created in your namespace:
Example output:
View the Repository CR details:
First, get the repository name from the list above, then view details:
Replace <repo-name> with the actual repository name from the list (e.g., my-repo).
Example output (abbreviated):
Check GitLab Webhook
- Go to your GitLab project → Settings → Webhooks
- Verify a webhook was created with:
- URL: Your PAC controller URL
- Trigger: Push events, Merge request events, Comments
- Secret token: The webhook secret you configured
Check Kubernetes Secret
When using tkn pac create repo, a secret is automatically created with your GitLab credentials. Verify the secret:
Example output:
View secret details:
Replace <secret-name> with the actual secret name (typically matches your repository name).
Example output (values are base64 encoded):
The secret contains:
provider.token: Your GitLab personal access tokenwebhook.secret: The webhook validation secret
Check Generated Template
Verify the .tekton/pipelinerun.yaml template was created in your repository:
Example output:
Step 6: Test the Configuration
Test Webhook Connection
You can test the webhook from GitLab:
- Go to GitLab project → Settings → Webhooks
- Find your PAC webhook
- Click Test → Push events
- Check the webhook response
Trigger a Test Pipeline
Create a simple commit to trigger a pipeline:
Check if a PipelineRun was created:
Example output:
Manual Configuration (Alternative)
If you prefer to configure manually or need more control, you can create the Repository CR and configure the webhook separately.
Create Repository CR Manually
Create a file repository.yaml:
Apply the CR:
Example output:
Create GitLab Secret
Create a secret with your GitLab token:
Example output:
Create Webhook Secret
Example output:
Configure GitLab Webhook Manually
- Go to GitLab project → Settings → Webhooks
- Add a new webhook:
- URL:
http://pac.example.com - Secret token: The webhook secret from above
- Trigger: Select "Push events" and "Merge request events"
- URL:
- Click Add webhook
Using Private Repositories
PAC supports private GitLab repositories. To configure authentication for private repositories, see the Configure Authentication for Private Repositories guide.
This guide covers authentication methods that work across all Git providers, including:
- Personal Access Token (PAT) authentication
- SSH key authentication
- Verification steps and troubleshooting
Interfacing with Custom Certificates
If your GitLab instance uses self-signed certificates or custom CA certificates, you need to configure PAC to trust these certificates. See the Configure Custom Certificates guide for detailed instructions.
This guide covers:
- Creating ConfigMaps with CA certificates
- Mounting certificates in PAC controller pods
- Configuring Git to use custom certificates
- Verification and troubleshooting steps
Troubleshooting
Check if Repository CR is Not Created
Check for errors:
Example output (abbreviated):
Check if Webhook is Not Configured
If the webhook wasn't created automatically:
- Verify the GitLab token has
apiscope - Check the token is valid:
curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/user" - Manually create the webhook (see Manual Configuration above)
Check if Webhook Events are Not Received
-
Check PAC controller logs:
Example output:
- Verify webhook URL is accessible from GitLab
- Check webhook secret matches in both GitLab and Repository CR
Check if PipelineRuns are Not Created
-
Check Repository CR:
Example output (abbreviated):
- Check PAC controller logs for errors
- Verify
.tekton/pipelinerun.yamlexists in your repository - Check namespace permissions
Check if Private Repository Access Issues
- Verify token permissions: Ensure the token has
apiscope - Check secret exists: Verify the authentication secret exists in the namespace
- Review Repository CR: Ensure the secret is correctly referenced
- Check PAC logs: Look for authentication errors in controller logs
For more details, see Configure Authentication for Private Repositories.
Check if Certificate Issues
- Verify certificate mount: Check that the certificate is mounted in the pod
- Check certificate validity: Ensure the certificate is not expired
- Verify Git configuration: Check that Git is configured to use the certificate
- Review logs: Look for SSL/certificate errors in PAC controller logs
For more details, see Configure Custom Certificates.
Next Steps
- Configure Authentication for Private Repositories - Configure authentication for private repositories
- Configure Custom Certificates - Configure custom CA certificates
- Maintain Pipeline Code - Learn how to define pipelines in your repository
- Trigger Pipelines - Learn about different trigger methods
- Common Issues - Troubleshooting guide