Jul 18, 2019 Options: If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to BitBucket, then generate a new SSH key.; If you see an existing public and private key pair listed (for example idrsa.pub and idrsa) that you would like to use to connect to BitBucket, you can add your SSH key to the ssh-agent. Add key to BitBucket. On BitBucket, choose avatar Manage Account. Switch to the account you want to manage and click SSH keys; add a new key which should be named to match the server name (e.g., dev.foodomain.com). Paste the key into the Key field and click Add key. Clone BitBucket repo.
June, 2017 update: Setup SSH key for local dev box and use agent forwarding for servers
Create/setup the key on your server:
- Login to server using SSH/terminal.
- Depending on your setup, you may need to
$ su -
and enter the root user’s password (depending on the steps you take below, this will create files in that user’s home directory with root permissions). - List the contents of
.ssh
directory:$ ls -a ~/.ssh
and check for an existingid_rsa.pub
; use that default identity in BitBucket (skip to next heading) or … - At the command prompt, type:
$ ssh-keygen
. - Follow the on-screen instructions (on a production machine, a password should be entered for security purposes).
- For comparison’s sake, list the contents of
.ssh
directory:$ ls -a ~/.ssh
. - Check to see if
ssh-agent
is running:$ ps -e | grep [s]sh-agent
. - If not (above command returns nothing) then run:
ssh-agent /bin/bash
. - Add newly-created key to the
ssh-agent
:$ ssh-add ~/.ssh/id_rsa
. - View list of keys the
ssh-agent
is managing:$ ssh-add -l
. - Run
$ cat ~/.ssh/id_rsa.pub
and copy the output to your clipboard.
Reversing the above process is easy:
Add key to BitBucket
- On BitBucket, choose
avatar
>Manage Account
. - Switch to the account you want to manage and click
SSH keys
; add a new key which should be named to match the server name (e.g.,dev.foodomain.com
). - Paste the key into the
Key
field and clickAdd key
.
Clone BitBucket repo
- Go to your repo in BitBucket and copy the
SSH
URI (e.g.,git@bitbucket.org:user-name/repo-name.git
). - SSH to your server and navigate to the location you want to clone the repo to.
- From the command line, run:
$ git clone git@bitbucket.org:user-name/repo-name.git
. Note: If you want to specify the folder name that the repo clones into, add that to the end of the command (e.g.,git clone git@bitbucket.org:user-name/repo-name.git target-folder-name
).
Done!
Pulling updates
- SSH to your server.
- Navigate to your repo:
$ cd target-folder-name/
. - Run
$ git remote update && git status
$ git fetch
. - If there are changes to pull, then run
$ git pull
. - Optionally re-run
$ git remote update && git status
$ git fetch && git pull
to see if everything is clean.
Links
Clone this wiki locally
This is a starting point for using Bitbucket Pipelines in a Java project thatuses Maven. It does the following:
- Automatic tasks:
- All branches: Build the project (
mvn clean verify
) master
branch: Deploy the build artifact (mvn deploy
)
- All branches: Build the project (
- Manual tasks (can be invoked within the Bitbucket UI):
- Release major version
- Release minor version
- Release patch
![Git Ssh Key Generation Bitbucket Git Ssh Key Generation Bitbucket](https://confluence.atlassian.com/bitbucket/files/304578655/773982634/2/1502738504211/pageant_runs.png)
The manual release tasks
- Incrememnt the major, minor, or patch component of the
version
propertyin the project's pom.xml - Commit the change to pom.xml to
develop
- Tag
develop
with the updated version - Merge
develop
intomaster
![Windows Windows](https://confluence.atlassian.com/bitbucket/files/304578655/755335794/2/1502737357377/add_ssh_key.png)
For this to work, you should follow these rules:
- Create a new branch for all new features, bugfixes, etc.
- Merge branches into
develop
only. Don't merge directly intomaster
. - Don't merge branches with broken builds into
develop
. - Only use semver versions in pom.xml, but stick to
MAJOR.MINOR.PATCH
(no suffixes, e.g.-beta
) otherwise version bumpingwill fail. - Don't use snapshot versions.
To set up an Artifactory server and to configure Java projects for deploymentto Artifactory, seesteve-taylor/artifact-server-config.
Configuring Bitbucket Pipelines
bitbucket-pipelines.yml by itself isn't quite enough to fully configure yourproject for Bitbucket Pipelines. You will need to provide some additionalsettings in Bitbucket.
Bitbucket Ssh Setup
Environment variables
The following environment variables need to be set withing Bitbucket.Fortunately, you can set all of these at the team level and they will beapplied to all repositories within the team.
Name | Example | Description |
---|---|---|
DEPLOYER_NAME | Deploy Bot | Deployment script name (appears in git logs) |
DEPLOYER_EMAIL | deploybot@example.com | Deployment script email address (appears in git logs) |
MAVEN_REPO_URL | https://artifactory.example.com/artifactory | Maven repository URL |
MAVEN_REPO_RELEASES_KEY | libs-release | Public releases cache repo ID |
MAVEN_SETTINGS_PROFILE | artifactory | Profile name |
MAVEN_REPO_READER_USERNAME | me | CI/CD Maven read-only username |
MAVEN_REPO_READER_PASSWORD | swordfish | CI/CD Maven read-only password |
MAVEN_REPO_PUBLISHER_USERNAME | cicd | CI/CD Maven read-write username |
MAVEN_REPO_PUBLISHER_PASSWORD | super-secret | CI/CD Maven read-write password |
MAVEN_REPO_RELEASES_LOCAL_KEY | libs-release-local | Private releases repo ID |
ssh
Unfortunately, the ssh keys provided by Bitbucket Pipelines don't allow tasksto push back to their git repository. You will need to generate a new ssh keypair that allows Bitbucket Pipelines to push to git.
- Go to Settings / Security / SSH keys in your Bitbucket team.
- Click Add key
- Generate an ssh key pair and paste the public key into into the Keyfield. (The dialog contains links to instructions to generate an ssh keypair.)
- Provide a label and click Add key to finish adding the team-level sshkey.
- Navigate to your repo and go to Settings / Pipelines / SSH keys.
- If there is already a key, delete it.
- Provide the private and public keys from step 2.
For additional projects, repeat steps 5 to 7.
![Git Ssh Key Generation Bitbucket Git Ssh Key Generation Bitbucket](http://guganeshan.com/blog/wp-content/uploads/2013/09/select-Git-components-during-installation-guganeshan_thumb.jpg)
Create Ssh Key For Git
Note: Bitbucket will log warnings each time it pushes using the team-levelssh key, as it is a deprecated feature and they unfortunately recommend usingan individual account's ssh key instead. You're quite welcome to follow thatrecommendation if it makes you sleep better at night.