Personal access tokens (PATs) provide a way to authenticate and authorize programmatic access to Gitpod. You can use PATs as an alternative to using your password for authentication when using the Gitpod CLI or API.
Use a PAT to authenticate your CI/CD pipeline with Gitpod. This allows your automated workflows to create, manage, or interact with Gitpod environments without requiring manual authentication.Example:
Integrate Gitpod with third-party development tools or services that need to access your Gitpod account. The PAT allows these tools to authenticate and perform actions on your behalf using the Gitpod CLI.Example (using a hypothetical code review tool):
Copy
Ask AI
import subprocessfrom code_review_tool import CodeReviewClient# Initialize code review clientcr_client = CodeReviewClient(api_key="code_review_api_key")# Gitpod PATGITPOD_PAT = "your_gitpod_pat"# When a new code review is createddef on_new_review(review): # Login to Gitpod CLI using PAT subprocess.run(["gitpod", "login", "--token", GITPOD_PAT], check=True) # Create a Gitpod environment for the review result = subprocess.run( ["gitpod", "environment", "create", review.repo_url, "--dont-wait"], capture_output=True, text=True, check=True ) # Extract the environment ID from the CLI output env_id = result.stdout.strip() # Get the environment details result = subprocess.run( ["gitpod", "environment", "get", env_id, "-o", "json"], capture_output=True, text=True, check=True ) import json env_details = json.loads(result.stdout) # Add the Gitpod environment URL to the review cr_client.add_comment(review.id, f"Gitpod environment: {env_details['url']}")