# bitbucket-pipelines ## Docker ``` # 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 ``` ## SSH run ### Basic example ``` script: - pipe: atlassian/ssh-run:0.2.6 variables: SSH_USER: 'ec2-user' SERVER: '127.0.0.1' COMMAND: 'echo $HOSTNAME' ``` ### Advanced example ``` 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' ```