Bitbucket Pipelines でパイプを使用する

What Are Pipes?

Pipes are pre-built actions designed to simplify pipeline configuration. They provide a straightforward way to integrate third-party tools and services into your CI/CD workflow.

The simplest way to configure your pipeline is to use pipes. You just paste the pipe, supply a few key pieces of information, and the rest is done for you.

Why Use Pipes?

  • Simplicity: No need to write complex scripts for common tasks

  • Reliability: Pre-built and tested by the community or vendors

  • Consistency: Standardized way to integrate services

  • Maintenance: Updates handled by pipe maintainers

  • Speed: Get integrations working quickly

How to Use Pipes

Pipes are used in your bitbucket-pipelines.yml file using the pipe keyword:

pipelines: default: - step: script: - pipe: atlassian/aws-s3-deploy:1.1.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: 'us-east-1' S3_BUCKET: 'my-bucket' LOCAL_PATH: 'dist'

AWS Pipes

AWS S3 Deploy

Deploy static files to Amazon S3:

- step: name: Deploy to S3 script: - npm run build - pipe: atlassian/aws-s3-deploy:1.1.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: 'us-west-2' S3_BUCKET: 'my-website-bucket' LOCAL_PATH: 'dist'

AWS Elastic Beanstalk デプロイ

- step: name: Deploy to Elastic Beanstalk script: - pipe: atlassian/aws-elasticbeanstalk-deploy:1.0.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: 'us-east-1' APPLICATION_NAME: 'my-app' ENVIRONMENT_NAME: 'production' ZIP_FILE: 'application.zip'

AWS Lambda デプロイ

- step: name: Deploy Lambda Function script: - pipe: atlassian/aws-lambda-deploy:1.2.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: 'us-east-1' FUNCTION_NAME: 'my-function' ZIP_FILE: 'function.zip'

AWS ECS Deploy

- step: name: Deploy to ECS script: - pipe: atlassian/aws-ecs-deploy:1.6.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: 'us-east-1' CLUSTER_NAME: 'my-cluster' SERVICE_NAME: 'my-service' TASK_DEFINITION: 'my-task'

Azure Pipes

Azure Web Apps Deploy

- step: name: Deploy to Azure script: - pipe: microsoft/azure-web-apps-deploy:1.0.0 variables: AZURE_APP_ID: $AZURE_APP_ID AZURE_PASSWORD: $AZURE_PASSWORD AZURE_TENANT_ID: $AZURE_TENANT_ID AZURE_RESOURCE_GROUP: 'my-resource-group' AZURE_APP_NAME: 'my-web-app'

Google Cloud Pipes

GCP Cloud Run Deploy

- step: name: Deploy to Cloud Run script: - pipe: atlassian/google-cloud-run-deploy:1.0.0 variables: KEY_FILE: $GCP_KEY_FILE PROJECT: 'my-project' SERVICE: 'my-service' REGION: 'us-central1' IMAGE: 'gcr.io/my-project/my-image:latest'

GCP App Engine Deploy

- step: name: Deploy to App Engine script: - pipe: atlassian/google-app-engine-deploy:1.0.0 variables: KEY_FILE: $GCP_KEY_FILE PROJECT: 'my-project'

Kubernetes Pipes

Kubectl Deploy

- step: name: Deploy to Kubernetes script: - pipe: atlassian/kubectl-run:3.2.0 variables: KUBE_CONFIG: $KUBE_CONFIG KUBECTL_COMMAND: 'apply' RESOURCE_PATH: 'k8s/deployment.yaml'

Docker Pipes

Docker Build and Push

- step: name: Build and Push Docker Image script: - pipe: atlassian/docker-build-push:0.1.0 variables: DOCKER_HUB_USERNAME: $DOCKER_HUB_USERNAME DOCKER_HUB_PASSWORD: $DOCKER_HUB_PASSWORD IMAGE_NAME: 'mycompany/myapp' TAGS: '$BITBUCKET_BUILD_NUMBER latest'

Slack Pipes

Slack Notify

- step: name: Notify Slack script: - npm test - pipe: atlassian/slack-notify:2.0.0 variables: WEBHOOK_URL: $SLACK_WEBHOOK_URL MESSAGE: 'Build $BITBUCKET_BUILD_NUMBER completed successfully!'

Security Scanning Pipes

Snyk Security Scan

- step: name: Security Scan script: - pipe: snyk/snyk-scan:1.0.0 variables: SNYK_TOKEN: $SNYK_TOKEN LANGUAGE: 'node'

SonarQube Scan

- step: name: Code Quality Analysis script: - pipe: sonarsource/sonarcloud-scan:1.4.0 variables: SONAR_TOKEN: $SONAR_TOKEN SONAR_SCANNER_OPTS: '-Dsonar.projectKey=my-project'

Notification Pipes

Email Notification

- step: name: Send Email script: - pipe: atlassian/email-notify:0.5.0 variables: USERNAME: $EMAIL_USERNAME PASSWORD: $EMAIL_PASSWORD FROM: 'builds@company.com' TO: 'team@company.com' SUBJECT: 'Build $BITBUCKET_BUILD_NUMBER' BODY: 'Build completed successfully'

Pipe Configuration

Basic Structure

- pipe: vendor/pipe-name:version variables: VARIABLE_NAME: 'value' ANOTHER_VARIABLE: $SECURED_VARIABLE

Debug Mode

Enable debug output for troubleshooting:

- pipe: atlassian/aws-s3-deploy:1.1.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY S3_BUCKET: 'my-bucket' LOCAL_PATH: 'dist' DEBUG: 'true'

Multiple Pipes in One Step

pipelines: default: - step: name: Build, Deploy, and Notify script: - npm run build - pipe: atlassian/aws-s3-deploy:1.1.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY S3_BUCKET: 'my-bucket' LOCAL_PATH: 'dist' - pipe: atlassian/slack-notify:2.0.0 variables: WEBHOOK_URL: $SLACK_WEBHOOK_URL MESSAGE: 'Deployed to S3 successfully!'

Conditional Pipes

Run pipes based on conditions:

pipelines: branches: main: - step: script: - npm run build - pipe: atlassian/aws-s3-deploy:1.1.0 variables: S3_BUCKET: 'production-bucket' LOCAL_PATH: 'dist' develop: - step: script: - npm run build - pipe: atlassian/aws-s3-deploy:1.1.0 variables: S3_BUCKET: 'staging-bucket' LOCAL_PATH: 'dist'

Creating Custom Pipes

You can create your own pipes to share common functionality across pipelines.

Pipe Structure

A pipe is essentially a Docker container with a specific interface:

FROM alpine:3.14 COPY pipe.sh /pipe.sh RUN chmod +x /pipe.sh ENTRYPOINT ["/pipe.sh"]

Example Custom Pipe

pipe.sh:

#!/bin/bash set -e # Read pipe variables API_URL=${API_URL:?'API_URL variable missing.'} API_KEY=${API_KEY:?'API_KEY variable missing.'} # Perform action curl -X POST "$API_URL" \ -H "Authorization: Bearer $API_KEY" \ -d '{"status": "deployed"}' echo "Notification sent successfully!"

Using Custom Pipe

- pipe: mycompany/custom-notify-pipe:1.0.0 variables: API_URL: 'https://api.example.com/notify' API_KEY: $API_KEY

Finding Pipes

Bitbucket Pipe Marketplace

Browse available pipes at:

  • Bitbucket UI: Repository → Pipelines → Pipes

  • Atlassian Marketplace: Search for "Bitbucket Pipes"

  • Atlassian: AWS, Azure, GCP integrations

  • Microsoft: Azure services

  • Snyk: Security scanning

  • SonarSource: Code quality

  • HashiCorp: Terraform, Vault

ベスト プラクティス

  1. Pin versions: Always specify exact pipe versions for reproducibility

  2. Use secured variables: Store sensitive data as secured variables

  3. Check documentation: Read pipe documentation for available options

  4. Test in staging: Verify pipe configuration before production

  5. Monitor pipe updates: Keep track of new versions and features

  6. Cache pipe images: Pipes are Docker images and benefit from caching

  7. Handle failures: Add error handling for pipe failures

  8. Use debug mode: Enable DEBUG for troubleshooting

トラブルシューティング

Pipe Not Found

Ensure you're using the correct pipe name and version:

# Correct - pipe: atlassian/aws-s3-deploy:1.1.0 # Incorrect - pipe: aws-s3-deploy:latest

Missing Variables

Check that all required variables are provided:

- pipe: atlassian/aws-s3-deploy:1.1.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID # Required AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Required S3_BUCKET: 'my-bucket' # Required LOCAL_PATH: 'dist' # Required

Authentication Failures

Verify credentials are correct and have necessary permissions:

variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID # Check in repository settings AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Ensure secured

次のステップ

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。