open:bitbucket-pipelines

bitbucket-pipelines

# This is a sample build configuration for Docker.
# Check our guides at https://confluence.atlassian.com/x/O1toN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2

pipelines:
  default:
    - step:
        services:
          - docker
        script: # Modify the commands below to build your repository.
          # Set $DOCKER_HUB_USERNAME and $DOCKER_HUB_PASSWORD as environment variables in repository settings
          - export IMAGE_NAME=your-Dockerhub-account/your-docker-image-name:$BITBUCKET_COMMIT

          # build the Docker image (this will use the Dockerfile in the root of the repo)
          - docker build -t $IMAGE_NAME .
          # authenticate with the Docker Hub registry
          - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
          # push the new Docker image to the Docker registry
          - docker push $IMAGE_NAME
script:
  - pipe: atlassian/ssh-run:0.2.6
    variables:
      SSH_USER: 'ec2-user'
      SERVER: '127.0.0.1'
      COMMAND: 'echo $HOSTNAME'
script:
  - pipe: atlassian/ssh-run:0.2.6
    variables:
      SSH_USER: 'ec2-user'
      SERVER: '127.0.0.1'
      SSH_KEY: $MY_SSH_KEY
      MODE: 'script'
      COMMAND: 'myscript.sh' # path to a script in your repository

The following example shows how to execute a bash script that is already on your remote server:

script:
  - pipe: atlassian/ssh-run:0.2.6
    variables:
      SSH_USER: 'ec2-user'
      SERVER: '127.0.0.1'
      MODE: 'command'
      COMMAND: './remote-script.sh'

Passing your local environment variable $LOCALVAR to the remote server and executing a bash command echo ${MYVAR} on the remote server:

script:
  - pipe: atlassian/ssh-run:0.2.6
    variables:
      SSH_USER: 'ec2-user'
      SERVER: '127.0.0.1'
      COMMAND: 'export MYVAR='"'${LOCALVAR}'"'; echo ${MYVAR}'

Note! Be careful, $LOCALVAR shouldn't contain any single quotes inside.

Invocating your local environment variables to the script with envsubst and executing a bash script on the remote server:

script:
  - envsubst < .contrib/deploy.sh > deploy-out.sh

  - pipe: atlassian/ssh-run:0.2.6
    variables:
      SSH_USER: 'ec2-user'
      SERVER: '127.0.0.1'
      MODE: 'script'
      COMMAND: 'deploy-out.sh'

  • open/bitbucket-pipelines.txt
  • 마지막으로 수정됨: 2020/09/09 06:54
  • 저자 127.0.0.1