I have faced an issue during the execution of my Bitbucket Pipelines build.
The target host is running a Windows operating system.
However, I am facing a problem where none of the commands are executed after establishing an SSH connection.
Below is the relevant section of the Bitbucket Pipeline:
# Bitbucket Pipeline Configuration
image: python:3.8
# Define the pipelines configuration. In this case, we specify a configuration for different branches.
pipelines:
# Define the branches section to configure how the pipeline behaves based on different branches.
branches:
# Specify that the following configuration applies to the 'develop' branch.
develop:
- step:
script:
- pipe: atlassian/ssh-run:0.6.1
variables:
SSH_USER: $SSH_USER
SERVER: $SERVER
PORT: $PORT
COMMAND: |
cd "C:\Users\User\PycharmProjects"
mkdir test-mohammad
echo "Clone the repository"
git clone --branch develop git@bitbucket.org:maytronicswt/o3_module.git
cd "C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE"
echo "Start Build Project"
stm32cubeide --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data "C:\Users\User\STM32CubeIDE\workspace_1.13.0" -build OSv2_STM32_Ozone_Module_v3
timeout /t 14
echo "End Build Project"
cd "C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin"
echo "Start Download to STM32"
STM32_Programmer_CLI.exe --connect port=SWD freq=4000KHz mode=Normal reset=sw mode=UR speed=Reliable shared=Disable --erase all --download "C:\Users\User\PycharmProjects\o3_module\Debug\OSv2_STM32_Ozone_Module_v3.elf"
echo "End Download to STM32"
Below the following error message:
+ umask 000
+ GIT_LFS_SKIP_SMUDGE=1 retry 6 git clone --branch="main" --depth 50 https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/$BITBUCKET_REPO_FULL_NAME.git $BUILD_DIR
Cloning into '/opt/atlassian/pipelines/agent/build'...+ git reset --hard 40c3472f2da9f5e424ec8caf8c90ec6d0aeedb7b
HEAD is now at 40c3472 https://bitbucket.org/maytronicswt/mohammad-o3-module-test/src/40c3472f2da9f5e424ec8caf8c90ec6d0aeedb7b/bitbucket-pipelines.yml edited online with Bitbucket+ 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
Default variables:
BITBUCKET_BRANCH
BITBUCKET_BUILD_NUMBER
BITBUCKET_CLONE_DIR
BITBUCKET_COMMIT
BITBUCKET_GIT_HTTP_ORIGIN
BITBUCKET_GIT_SSH_ORIGIN
BITBUCKET_PIPELINE_UUID
BITBUCKET_PROJECT_KEY
BITBUCKET_PROJECT_UUID
BITBUCKET_REPO_FULL_NAME
BITBUCKET_REPO_IS_PRIVATE
BITBUCKET_REPO_OWNER
BITBUCKET_REPO_OWNER_UUID
BITBUCKET_REPO_SLUG
BITBUCKET_REPO_UUID
BITBUCKET_SSH_KEY_FILE
BITBUCKET_STEP_RUN_NUMBER
BITBUCKET_STEP_TRIGGERER_UUID
BITBUCKET_STEP_UUID
BITBUCKET_WORKSPACE
CI
DOCKER_HOST
PIPELINES_JWT_TOKENRepository variables:
PORT
SERVER
SSH_USERImages used:
build : docker.io/library/python@sha256:7a82536f5a2895b70416ccaffc49e6469d11ed8d9bf6bcfc52328faeae7c7710
+ docker container run \
--volume=/opt/atlassian/pipelines/agent/build:/opt/atlassian/pipelines/agent/build \
--volume=/opt/atlassian/pipelines/agent/ssh:/opt/atlassian/pipelines/agent/ssh:ro \
--volume=/usr/local/bin/docker:/usr/local/bin/docker:ro \
--volume=/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes:/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes \
--volume=/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlassian/ssh-run:/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlassian/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_SSH_KEY_FILE="$BITBUCKET_SSH_KEY_FILE" \
--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/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes" \
--env=BITBUCKET_PIPE_STORAGE_DIR="/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/atlassian/ssh-run" \
--env=COMMAND="cd \"C:\Users\User\PycharmProjects\"
mkdir test-mohammad
echo \"Clone the repository\"
git clone --branch develop git@bitbucket.org:maytronicswt/o3_module.git
cd \"C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE\"
echo \"Start Build Project\"
stm32cubeide --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data \"C:\Users\User\STM32CubeIDE\workspace_1.13.0\" -build OSv2_STM32_Ozone_Module_v3
timeout /t 14
echo \"End Build Project\"
cd \"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\"
echo \"Start Download to STM32\"
STM32_Programmer_CLI.exe --connect port=SWD freq=4000KHz mode=Normal reset=sw mode=UR speed=Reliable shared=Disable --erase all --download \"C:\Users\User\PycharmProjects\o3_module\Debug\OSv2_STM32_Ozone_Module_v3.elf\"
echo \"End Download to STM32\"
" \
--env=PORT="$PORT" \
--env=SERVER="$SERVER" \
--env=SSH_USER="$SSH_USER" \
--add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
bitbucketpipelines/ssh-run:0.6.1
Unable to find image 'bitbucketpipelines/ssh-run:0.6.1' locally
0.6.1: Pulling from bitbucketpipelines/ssh-run
31603596830f: Pulling fs layer
0a21ce3fb6b7: Pulling fs layer
95fed1a6facc: Pulling fs layer
a2856bd0c274: Pulling fs layer
a2856bd0c274: Waiting
95fed1a6facc: Download complete
31603596830f: Verifying Checksum
31603596830f: Download complete
0a21ce3fb6b7: Verifying Checksum
0a21ce3fb6b7: Download complete
31603596830f: Pull complete
a2856bd0c274: Verifying Checksum
a2856bd0c274: Download complete
0a21ce3fb6b7: Pull complete
95fed1a6facc: Pull complete
a2856bd0c274: Pull complete
Digest: sha256:d4448bda87989255fe8a4d10e6ab9d84d24cd2355b3c5a47d2728f8cad1577b4
Status: Downloaded newer image for bitbucketpipelines/ssh-run:0.6.1
[36mINFO: Executing the pipe...[0m
[36mINFO: Using default ssh key[0m
[36mINFO: Executing command on $SERVER[0m
ssh -A -tt -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p <my port> <my_user>@$SERVER bash -c 'cd "C:\Users\User\PycharmProjects"
mkdir test-mohammad
echo "Clone the repository"
git clone --branch develop git@bitbucket.org:maytronicswt/o3_module.git
cd "C:\ST\STM32CubeIDE_1.13.0\STM32CubeIDE"
echo "Start Build Project"
stm32cubeide --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data "C:\Users\User\STM32CubeIDE\workspace_1.13.0" -build OSv2_STM32_Ozone_Module_v3
timeout /t 14
echo "End Build Project"
cd "C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin"
echo "Start Download to STM32"
STM32_Programmer_CLI.exe --connect port=SWD freq=4000KHz mode=Normal reset=sw mode=UR speed=Reliable shared=Disable --erase all --download "C:\Users\User\PycharmProjects\o3_module\Debug\OSv2_STM32_Ozone_Module_v3.elf"
echo "End Download to STM32"
'
Warning: Permanently added '[$SERVER]:<'my_port'>' (ECDSA) to the list of known hosts.
[2J[m[H'bash' is not recognized as an internal or external command,
operable program or batch file.
]0;C:\Windows\system32\conhost.exe[?25h[32m✔ Execution finished.[0m
Connection to $SERVER closed.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.
In additional to the previous answer about bash required for the pipe.
It's better way to put commands you want to execute into file myscript.sh and use MODE script:
script:
- chmod 005 myscript.sh - pipe: atlassian/ssh-run:0.7.1 variables: SSH_USER: 'ec2-user' SERVER: '127.0.0.1' MODE: 'script' COMMAND: 'myscript.sh' # path to a script in your repository
If you want to invoke data from the environment variable, you could use:
script: - envsubst < .contrib/deploy.sh.template > deploy-out.sh
Best regards,
Oleksandr Kyrdan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Mohammad Sharabati and thank you for reaching out to the community!
The pipe you are using atlassian/ssh-run uses the bash shell to execute the command/script you have defined in the pipe. Bash is a native UNIX shell and is not included in Windows by default, so this is the reason why the pipe is failing with the following error :
'bash' is not recognized as an internal or external command,
operable program or batch file.
You could try to use Windows Subsystem for Linux to install bash in your Windows instance, as described in the following article :
Once the Windows host is able to execute bash commands, the pipe should be able to run successfully.
Hope that helps! Let us know in case you have any questions.
Thank you, @Mohammad Sharabati !
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.
@Patrik S
I've faced a new issue after installing WSL and adding the script.
Please refer to the issue below:
Status: Downloaded newer image for bitbucketpipelines/ssh-run:0.6.1
INFO: Executing the pipe...
INFO: Using default ssh key
INFO: Executing script script.sh on $SERVER
ssh -A -tt -i /root/.ssh/pipelines_id -o StrictHostKeyChecking=no -p <port> <user>@$SERVER bash -c './script.sh'
The file cannot be accessed by the system.
✖ Execution failed.
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.
@Mohammad Sharabati hi. Seems like problem related to WSL after you installed bash.
Check this article and all related search to ssh windows The file cannot be accessed by the system.
Regards, Igor
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.