hi
after every commit i have to run Repetitious commands to deploy vue.js app on server via ssh
but i want after each commit, codes automatically run and deploy
these are codes that i run in ssh:
cd crm
sudo rm -r nuxt-panel/
{{ask for ssh pass and i enter}}
sudo git pull
nBn23LnQEExJnK8nZnnnn
sudo yarn build
sudo pm2 delete web
pm2 start yarn --name web -- start
Hello @sia nami ,
Welcome to Atlassian Community.
Reading through the details you have provided I understand you want to run those commands remotely on an SSH server, using Bitbucket Pipelines, whenever a commit is pushed to your repository.
In order to achieve that, you will first have to create an SSH key to be used by pipelines when connecting to your SSH server. We have the following documentations with instructions on how to do it :
Once the SSH key is created, you will have to add the generated public key into the folder ~/.ssh/authorized_keys on the remote host. Also , you will have to add the address of your remote server to the pipelines known hosts, by going to Repository Settings > SSH keys > Add the address for the known host > Click the Fetch button.
Then, you can make use of the atlassian/ssh-run pipe in your YML file in order to execute a bash script that is already on your remote server:
pipelines:
default:
- step:
script:
- pipe: atlassian/ssh-run:0.4.0
variables:
SSH_USER: '<ssh_username>'
SERVER: '<SSH host address>'
MODE: 'command'
COMMAND: './remote-script.sh'
The pipeline above will connect to the SSH server and run the script remote-script.sh. This script should have the sequence of the commands that you currently execute manually and it must be already in the remote server.
In case you don't want to use a script file, you can define the commands directly on the pipe, as follow :
pipelines:
default:
- step:
script:
- pipe: atlassian/ssh-run:0.4.0
variables:
SSH_USER: '<ssh_username>'
SERVER: '<ssh_server>'
MODE: 'command'
COMMAND: 'cd $FOLDER && git pull && yarn build'
For more example and details on how to use the atlassian/ssh-run pipe, you can refer to the below documentation :
Hope that helps. Let us know in case you run into any issues.
Thanks, @sia nami
Patrik S.
hi
pipeline didnt work and show error what is issue?
i added bitbucket-pipelines.yml to root folder with below code:
pipelines:
default:
- step:
script:
- pipe: atlassian/ssh-run:0.4.0
variables:
SSH_USER: 'ssh_username'
SERVER: 'ssh_server'
MODE: 'command'
COMMAND: 'cd crm/cs.frontend/ && sudo rm -r nuxt-panel/ && sudo git pull && sudo yarn build && sudo pm2 delete web && pm2 start yarn --name web -- start'
this is build error tab:
+ umask 000
+ GIT_LFS_SKIP_SMUDGE=1 retry 6 git clone --branch="master" --depth 50 https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/$BITBUCKET_REPO_FULL_NAME.git $BUILD_DIR
Cloning into '/opt/atlas$ssh_usernamen/pipelines/agent/build'...
+ git reset --hard 86800dab8d2a8877606cc758f5a6ed0024690db1
HEAD is now at 86800da add bitbucket-pipelines.yml
+ git config user.name bitbucket-pipelines
+ git config user.email commits-noreply@bitbucket.org
+ git config push.default current
+ git config http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy http://localhost:29418/
+ git remote set-url origin http://bitbucket.org/$BITBUCKET_REPO_FULL_NAME
+ git reflog expire --expire=all --all
+ echo ".bitbucket/pipelines/generated" >> .git/info/exclude
+ chmod 777 $BUILD_DIR
Images used:
build : docker.io/atlas$ssh_usernamen/default-image@sha256:689e2c63e20a48e0a4d31156adcf32b4474dc32b50ab05abe3682b39fb9767a8
+ docker container run \
--volume=/opt/atlas$ssh_usernamen/pipelines/agent/build:/opt/atlas$ssh_usernamen/pipelines/agent/build \
--volume=/opt/atlas$ssh_usernamen/pipelines/agent/ssh:/opt/atlas$ssh_usernamen/pipelines/agent/ssh:ro \
--volume=/usr/local/bin/docker:/usr/local/bin/docker:ro \
--volume=/opt/atlas$ssh_usernamen/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes:/opt/atlas$ssh_usernamen/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes \
--volume=/opt/atlas$ssh_usernamen/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlas$ssh_usernamen/ssh-run:/opt/atlas$ssh_usernamen/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlas$ssh_usernamen/ssh-run \
--workdir=$(pwd) \
--label=org.bitbucket.pipelines.system=true \
--env=BITBUCKET_STEP_TRIGGERER_UUID="$BITBUCKET_STEP_TRIGGERER_UUID" \
--env=BITBUCKET_REPO_FULL_NAME="$BITBUCKET_REPO_FULL_NAME" \
--env=BITBUCKET_GIT_HTTP_ORIGIN="$BITBUCKET_GIT_HTTP_ORIGIN" \
--env=BITBUCKET_PROJECT_UUID="$BITBUCKET_PROJECT_UUID" \
--env=BITBUCKET_REPO_IS_PRIVATE="$BITBUCKET_REPO_IS_PRIVATE" \
--env=BITBUCKET_WORKSPACE="$BITBUCKET_WORKSPACE" \
--env=BITBUCKET_REPO_OWNER_UUID="$BITBUCKET_REPO_OWNER_UUID" \
--env=BITBUCKET_BRANCH="$BITBUCKET_BRANCH" \
--env=BITBUCKET_REPO_UUID="$BITBUCKET_REPO_UUID" \
--env=BITBUCKET_PROJECT_KEY="$BITBUCKET_PROJECT_KEY" \
--env=BITBUCKET_REPO_SLUG="$BITBUCKET_REPO_SLUG" \
--env=CI="$CI" \
--env=BITBUCKET_REPO_OWNER="$BITBUCKET_REPO_OWNER" \
--env=BITBUCKET_STEP_RUN_NUMBER="$BITBUCKET_STEP_RUN_NUMBER" \
--env=BITBUCKET_BUILD_NUMBER="$BITBUCKET_BUILD_NUMBER" \
--env=BITBUCKET_GIT_SSH_ORIGIN="$BITBUCKET_GIT_SSH_ORIGIN" \
--env=BITBUCKET_PIPELINE_UUID="$BITBUCKET_PIPELINE_UUID" \
--env=BITBUCKET_COMMIT="$BITBUCKET_COMMIT" \
--env=BITBUCKET_CLONE_DIR="$BITBUCKET_CLONE_DIR" \
--env=PIPELINES_JWT_TOKEN="$PIPELINES_JWT_TOKEN" \
--env=BITBUCKET_STEP_UUID="$BITBUCKET_STEP_UUID" \
--env=BITBUCKET_DOCKER_HOST_INTERNAL="$BITBUCKET_DOCKER_HOST_INTERNAL" \
--env=DOCKER_HOST="tcp://host.docker.internal:2375" \
--env=BITBUCKET_PIPE_SHARED_STORAGE_DIR="/opt/atlas$ssh_usernamen/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes" \
--env=BITBUCKET_PIPE_STORAGE_DIR="/opt/atlas$ssh_usernamen/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlas$ssh_usernamen/ssh-run" \
--env=COMMAND="cd crm/cs.cfbtel-frontend/ && sudo rm -r nuxt-panel/ && sudo git pull && sudo yarn build && sudo pm2 delete web && pm2 start yarn --name web -- start" \
--env=MODE="command" \
--env=SERVER="ssh_server" \
--env=SSH_USER="ssh_username" \
--add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
bitbucketpipelines/ssh-run:0.4.0
Unable to find image 'bitbucketpipelines/ssh-run:0.4.0' locally
0.4.0: Pulling from bitbucketpipelines/ssh-run
31603596830f: Pulling fs layer
c507f8e37a23: Pulling fs layer
7eca4d8c4c7b: Pulling fs layer
c21a713484c2: Pulling fs layer
c21a713484c2: Waiting
7eca4d8c4c7b: Verifying Checksum
7eca4d8c4c7b: Download complete
31603596830f: Verifying Checksum
31603596830f: Download complete
c507f8e37a23: Verifying Checksum
c507f8e37a23: Download complete
31603596830f: Pull complete
c21a713484c2: Verifying Checksum
c21a713484c2: Download complete
c507f8e37a23: Pull complete
7eca4d8c4c7b: Pull complete
c21a713484c2: Pull complete
Digest: sha256:2aa2f6517fb364da07a18f8b1e55b651c1db0361f7a850b79914c8da663f709e
Status: Downloaded newer image for bitbucketpipelines/ssh-run:0.4.0
[36mINFO: Executing the pipe... [0m
[36mINFO: Using default ssh key [0m
[36mINFO: Executing command on ssh_server [0m
ssh -A -tt -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p 22 ssh_username@ssh_server bash -c 'cd crm/cs.cfbtel-frontend/ && sudo rm -r nuxt-panel/ && sudo git pull && sudo yarn build && sudo pm2 delete web && pm2 start yarn --name web -- start'
ssh: Could not resolve hostname ssh_server: Name does not resolve
[31m✖ Execution failed. [0m
Searching for files matching artifact pattern .bitbucket/pipelines/generated/pipeline/pipes/**
Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4
Finished scanning for test reports. Found 0 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.
and this is for docker tab:
time="2022-01-27T15:30:34.903048174Z" level=warning msg="could not change group /var/run/docker.sock to docker: group docker not found"
time="2022-01-27T15:30:34.903388627Z" level=warning msg="Binding to IP address without --tlsverify is insecure and gives root access on this machine to everyone who has access to your network." host="tcp://0.0.0.0:2375"
time="2022-01-27T15:30:34.903447991Z" level=warning msg="Binding to an IP address, even on localhost, can also give access to scripts run in a browser. Be safe out there!" host="tcp://0.0.0.0:2375"
time="2022-01-27T15:30:35.903570776Z" level=warning msg="Binding to an IP address without --tlsverify is deprecated. Startup is intentionally being slowed down to show this message" host="tcp://0.0.0.0:2375"
time="2022-01-27T15:30:35.903616153Z" level=warning msg="Please consider generating tls certificates with client validation to prevent exposing unauthenticated root access to your network" host="tcp://0.0.0.0:2375"
time="2022-01-27T15:30:35.903627643Z" level=warning msg="You can override this by explicitly specifying '--tls=false' or '--tlsverify=false'" host="tcp://0.0.0.0:2375"
time="2022-01-27T15:30:35.903636182Z" level=warning msg="Support for listening on TCP without authentication or explicit intent to run without authentication will be removed in the next release" host="tcp://0.0.0.0:2375"
time="2022-01-27T15:30:50.961382340Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.devmapper" error="devmapper not configured"
time="2022-01-27T15:30:50.962123152Z" level=warning msg="could not use snapshotter devmapper in metadata plugin" error="devmapper not configured"
time="2022-01-27T15:30:50.964113555Z" level=warning msg="failed to load plugin io.containerd.internal.v1.opt" error="mkdir /opt/containerd: read-only file system"
time="2022-01-27T15:30:51.045159778Z" level=warning msg="Your kernel does not support CPU realtime scheduler"
time="2022-01-27T15:30:51.045190357Z" level=warning msg="Your kernel does not support cgroup blkio weight"
time="2022-01-27T15:30:51.045196847Z" level=warning msg="Your kernel does not support cgroup blkio weight_device"
time="2022-01-27T15:30:51Z" level=info msg="Pipelines plugin request authorization." allowed=false method=HEAD plugin=pipelines uri=/_ping
time="2022-01-27T15:30:51.728369278Z" level=error msg="AuthZRequest for HEAD /_ping returned error: authorization denied by plugin pipelines: "
time="2022-01-27T15:30:51Z" level=info msg="Pipelines plugin request authorization." allowed=true method=GET plugin=pipelines uri=/_ping
time="2022-01-27T15:30:51Z" level=info msg="Container create request." ArgsEscaped=false AttachStderr=true AttachStdin=false AttachStdout=true ExposedPorts="map[]" Healthcheck="<nil>" Labels="map[org.bitbucket.pipelines.system:true]" MacAddress= NetworkDisabled=false OnBuild="[]" OpenStdin=false StdinOnce=false StopSignal= StopTimeout="<nil>" Tty=false plugin=pipelines
time="2022-01-27T15:30:51Z" level=info msg="Container create request." AutoRemove=false BlkioDeviceReadBps="[]" BlkioDeviceReadIOps="[]" BlkioDeviceWriteBps="[]" BlkioDeviceWriteIOps="[]" BlkioWeight=0 BlkioWeightDevice="[]" CPUCount=0 CPUPercent=0 CPUPeriod=0 CPUQuota=0 CPURealtimePeriod=0 CPURealtimeRuntime=0 CPUShares=0 CapAdd="[]" CapDrop="[]" Cgroup= CgroupParent= ConsoleSize="[0 0]" ContainerIDFile= CpusetCpus= CpusetMems= DNS="[]" DNSOptions="[]" DNSSearch="[]" DeviceCgroupRules="[]" Devices="[]" ExtraHosts="[host.docker.internal:10.36.70.111]" GroupAdd="[]" IOMaximumBandwidth=0 IOMaximumIOps=0 Init="<nil>" IpcMode= Isolations= KernelMemory=0 Links="[]" LogConfig="{ map[]}" MaskedPaths="[]" Memory=0 MemoryReservation=0 MemorySwap=0 MemorySwappiness=0xc000256230 Mounts="[]" NanoCPUs=0 NetworkMode=default OomKillDisable=0xc00025623a OomScoreAdj=0 PidMode= PidsLimit=0xc000256240 PortBindings="map[]" Privileged=false PublishAllPorts=false ReadOnlyPaths="[]" RestartPolicy="{no 0}" Runtime= SecurityOpt="[]" ShmSize=0 StorageOpt="map[]" Sysctls="map[]" Ulimits="[]" UsernsMode= VolumeDriver= VolumesFrom="[]" plugin=pipelines
time="2022-01-27T15:30:51Z" level=info msg="Container create request." EndpointsConfig="map[]" plugin=pipelines
time="2022-01-27T15:30:51Z" level=info msg="Pipelines plugin request authorization." allowed=true method=POST plugin=pipelines uri=/v1.40/containers/create
time="2022-01-27T15:30:51.736103211Z" level=error msg="Handler for POST /v1.40/containers/create returned error: No such image: bitbucketpipelines/ssh-run:0.4.0"
time="2022-01-27T15:30:51Z" level=info msg="Pipelines plugin request authorization." allowed=true method=GET plugin=pipelines uri=/v1.40/info
time="2022-01-27T15:30:51Z" level=info msg="Pipelines plugin request authorization." allowed=true method=POST plugin=pipelines uri="/v1.40/images/create?fromImage=bitbucketpipelines%2Fssh-run&tag=0.4.0"
time="2022-01-27T15:30:53Z" level=info msg="Container create request." ArgsEscaped=false AttachStderr=true AttachStdin=false AttachStdout=true ExposedPorts="map[]" Healthcheck="<nil>" Labels="map[org.bitbucket.pipelines.system:true]" MacAddress= NetworkDisabled=false OnBuild="[]" OpenStdin=false StdinOnce=false StopSignal= StopTimeout="<nil>" Tty=false plugin=pipelines
time="2022-01-27T15:30:53Z" level=info msg="Container create request." AutoRemove=false BlkioDeviceReadBps="[]" BlkioDeviceReadIOps="[]" BlkioDeviceWriteBps="[]" BlkioDeviceWriteIOps="[]" BlkioWeight=0 BlkioWeightDevice="[]" CPUCount=0 CPUPercent=0 CPUPeriod=0 CPUQuota=0 CPURealtimePeriod=0 CPURealtimeRuntime=0 CPUShares=0 CapAdd="[]" CapDrop="[]" Cgroup= CgroupParent= ConsoleSize="[0 0]" ContainerIDFile= CpusetCpus= CpusetMems= DNS="[]" DNSOptions="[]" DNSSearch="[]" DeviceCgroupRules="[]" Devices="[]" ExtraHosts="[host.docker.internal:10.36.70.111]" GroupAdd="[]" IOMaximumBandwidth=0 IOMaximumIOps=0 Init="<nil>" IpcMode= Isolations= KernelMemory=0 Links="[]" LogConfig="{ map[]}" MaskedPaths="[]" Memory=0 MemoryReservation=0 MemorySwap=0 MemorySwappiness=0xc000121ee0 Mounts="[]" NanoCPUs=0 NetworkMode=default OomKillDisable=0xc000121eea OomScoreAdj=0 PidMode= PidsLimit=0xc000121ef0 PortBindings="map[]" Privileged=false PublishAllPorts=false ReadOnlyPaths="[]" RestartPolicy="{no 0}" Runtime= SecurityOpt="[]" ShmSize=0 StorageOpt="map[]" Sysctls="map[]" Ulimits="[]" UsernsMode= VolumeDriver= VolumesFrom="[]" plugin=pipelines
time="2022-01-27T15:30:53Z" level=info msg="Container create request." EndpointsConfig="map[]" plugin=pipelines
time="2022-01-27T15:30:53Z" level=info msg="Pipelines plugin request authorization." allowed=true method=POST plugin=pipelines uri=/v1.40/containers/create
time="2022-01-27T15:30:53Z" level=info msg="Pipelines plugin request authorization." allowed=true method=POST plugin=pipelines uri="/v1.40/containers/2d22ee6c8f3993c6a110c50a167b2a753c23d65754064030ecd4f38d3cc30562/attach?stderr=1&stdout=1&stream=1"
time="2022-01-27T15:30:53Z" level=info msg="Pipelines plugin request authorization." allowed=true method=POST plugin=pipelines uri="/v1.40/containers/2d22ee6c8f3993c6a110c50a167b2a753c23d65754064030ecd4f38d3cc30562/wait?condition=next-exit"
time="2022-01-27T15:30:53Z" level=info msg="Pipelines plugin request authorization." allowed=true method=POST plugin=pipelines uri=/v1.40/containers/2d22ee6c8f3993c6a110c50a167b2a753c23d65754064030ecd4f38d3cc30562/start
time="2022-01-27T15:30:53.294505414Z" level=info msg="starting signal loop" namespace=moby path=/run/docker/containerd/daemon/io.containerd.runtime.v2.task/moby/2d22ee6c8f3993c6a110c50a167b2a753c23d65754064030ecd4f38d3cc30562 pid=236
time="2022-01-27T15:30:53.850148751Z" level=error msg="copy shim log" error="read /proc/self/fd/12: file already closed"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @sia nami ,
From the error message in the logs, looks like the pipe had issues while resolving the SSH server hostname :
ssh: Could not resolve hostname ssh_server: Name does not resolve
That could be caused by different reasons :
pipelines:
default:
- step:
script:
- pipe: atlassian/ssh-run:0.4.0
variables:
SSH_USER: 'ssh_username'
SERVER: 'ssh_server'
MODE: 'command'
COMMAND: 'cd crm/cs.frontend/ && sudo rm -r nuxt-panel/ && sudo git pull && sudo yarn build && sudo pm2 delete web && pm2 start yarn --name web -- start'
Hope that helps. Let us know in case you have other questions.
Thanks, @sia nami
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.