Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,113
Community Members
 
Community Events
184
Community Groups

Newbie to Bitbucket Pipelines: Zip a repo and send to sftp site?

Like I said in the header, I'm a newbie to BitBucket pipelines. I need to write a pipeline that will zip up my current repo, then take that zip file and send it via sftp to our doc host. Does anyone have a sample script that might do some of those things? Or some docs talking about doing something like that?

 

Thaks,

 

Russ

1 answer

1 vote
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 09, 2022

G'day Russ!

Welcome to the Bitbucket Cloud community :)

As the pipeline is executed on a branch, the clone directory will contain all of the src files that belong to that branch and this will be the current working directory when you execute a build.

If you were to compress that branch, you could add the following command in your YML file to compress all of the files within the clone directory to a zip folder using zip command with recursive option:

 

- zip -r branchname.zip .
I would then suggest using the sftp-deploy pipe as documented below to send the resulting zip folder to your sftp server:
https://bitbucket.org/atlassian/sftp-deploy/src/master/
More information regarding pipes can be found here:
https://support.atlassian.com/bitbucket-cloud/docs/what-are-pipes/
Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

Thank you I will look at this. Is the pipes.yaml file, is that located in the same branch as well?

Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 10, 2022

Hey Russ,

Pipes are configured in the same bitbucket-pipelines.yml file as the rest of the build steps. This file is located in the same branch that you are executing the build steps :)

Cheers!

- Ben (Bitbucket Cloud Support)

I finally got back around to this. I wrote this pipeline to zip my current repo and then send to our host site. We have an SSH key associated with this host provider. Does this pipeline look like it will work:

 

# This is an example Starter pipeline configuration
# Use a skeleton to build, test and deploy using manual and parallel steps
# -----


pipelines:
default:
- parallel:
- step:
name: 'Test sending zip file to zoomin'
script:
- zip -r bundle.zip .
- pipe: atlassian/sftp-deploy:0.5.11
variables:
USER: 'boomi'
SERVER: 'upload.zoominsoftware.io'
REMOTE_PATH: 'boomi-be-staging.zoominsoftware.io/dita-vasont/incoming'
LOCAL_PATH: 'bundle.zip'
SSH_KEY: $BITBUCKET_SSH_KEY_FILE
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Nov 08, 2022

Hey Russ,

Provided the SSH key is correct this should be fine. I would suggest removing the parallel tag however as it is not needed, the zip command will be executed prior to running the pipe.

Please test this and let me know how it goes.

Cheers!

- Ben (Bitbucket Cloud Support)

I had to add some stuff, to add zip functionality. 

pipelines:
  default:
- step:
name: 'Test sending zip file to zoomin'
script:
- sudo apt-get update
- sudo apt-get install zip
- zip -r bundle.zip .
- pipe: atlassian/sftp-deploy:0.5.11
variables:
USER: '*****'
SERVER: '*****'
REMOTE_PATH: '*****'
LOCAL_PATH: 'bundle.zip'
SSH_KEY: $BITBUCKET_SSH_KEY_FILE


I am currently getting Hosting Authentication error. I made sure I put my private SSH key in the BITBUCKET_SSH_KEY_FILE repository variable. Got the same error. I made sure I did a base64 encode of my private key, then put THAT into the same variable. Same thing. When I pasted the private key with the linebreaks, I got a different error, so I know it is accessing the BITBUCKET_SSH_KEY_FILE.

I was able to sftp to that server and put a zip file in the desired location with no problem.

Is it possible that, the manner/encoding that BitBucket is expecting the private SSH key is not compatible with what server is expecting, and so it fails then?

Here is a screenshot:

image.png

Also should bundle.zip be saved an an artifact to be passed to the sftp pipe?

Any help is REALLY appreciated! 

Thank you so much!

 

Russ

This is still not working, can someone help me?

Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Nov 14, 2022

Hey Russ,

I have once again censored your output due to this being a public forum.

You will need to ensure that you generate an RSA SSH key with no passphrase using the following command:

ssh-keygen -t rsa -b 4096 -N '' -f my_ssh_key

Once complete, you will then need to encode the key in Base64:

base64 < my_ssh_key

Once done, you will then need to copy paste this into your repository variables.

After completion, you need to install the public SSH key on your remote server and add a my_known_hosts file to your Bitbucket Repo and commit it:

ssh-keyscan -t rsa server.example.com > my_known_hosts

A complete guide can be found here under "use multiple SSH keys in your pipeline":

https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#Use-multiple-SSH-keys-in-your-pipeline

Please follow the guide above step-by-step. Once complete, please let me know if you run into any further issues.

Cheers!

- Ben (Bitbucket Cloud Support)

 

Hi Ben,

my key was generated with 

`ssh-keygen -t rsa -b 4096 -m PEM`

giving a `id_rsa` and `id_rsa.pub`.  This key has no passphrase. Is this format ok?

I have done the base64 encoding, but will try it again. Do both the private AND public key need to be base64 encoded prior to putting their values into the Repository settings>SSH key section?

My public key is already on the remote server, as I can sftp from the command line.

My `~/.ssh` directory has a `known_hosts` file. I will add a unique `my_known_hosts` file on the repo.

I will give this a try and let you know!

 

Thanks again!

Russ

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events