- Install BitBucket
- Make a
Project
calledpuppet
(with a short name ofPUP
) - Create a repository called
control-repo
-
- Create a user called
r10k
with a password ofpuppet
. - Make the r10k user an admin of the
PUP
project.
- Create a user called
- Either use the admin user to test pushing code, or create a user for yourself and add your SSH key to that user.
- If making a user for yourself, give your user account read/write or admin privilege to the
PUP
project.
- If making a user for yourself, give your user account read/write or admin privilege to the
This is the preferred method.
NOTE: BitBucket has a new built-in webhook feature. It's similar to the functionality provided by the plugin. But, as of this writing (December 2018), Code Manager doesn't support the built-in webhooks and still requires the functionality provided by the plug-in.
- Install the following BitBucket Server plugin by logging into the web GUI of the Stash server and going to
Find new add-ons
.- Web Post Hooks for BitBucket Server
- You can also install it manually by downloading the JAR file. See Installing Marketplace apps in Atlassian's web site
- Add the Puppet Master's CA cert to the Java keystore on the BitBucket server:
-
Determine the $JAVA_HOME value used for BitBucket by looking in:
/opt/atlassian/bitbucket/<version>/bin/setenv.sh
.- You can also look at the
System Information
page of the Web GUI. In my case, it's/opt/atlassian/bitbucket/4.3.2/jre
.
- You can also look at the
-
Run the following command and replace
$JAVA_HOME
with the path from the previous step:$JAVA_HOME/bin/keytool -import -alias puppet-ca -file /etc/puppetlabs/puppet/ssl/certs/ca.pem -keystore $JAVA_HOME/lib/security/cacerts
- When asked for a password, use
changeit
.
- When asked for a password, use
-
- Restart the BitBucket service (check the Atlassian documentation to find the service name in your OS).
- Configure the hook on your control repo.
-
Click the
Hooks
tab under the repo's settings. -
Click the pencil icon next to
Post-Receive WebHooks
-
The URL to drop in should be in the format of:
https://puppet-master:8170/code-manager/v1/webhook?type=stash&token=<TOKEN>
- Replace <TOKEN> with the RBAC Token that was generated automatically for you (see
/etc/puppetlabs/puppetserver/.puppetlabs/deploy_token
)
- Replace <TOKEN> with the RBAC Token that was generated automatically for you (see
-
If, for some reason, you can't install the plugin or modify the Java Key Store, you can also use this method.
Be aware that, with this method, there's no way to inform Code Manager which branch was modified, so you have to hard code the branch name in the configuration. The alternative is to redeploy all branches (Puppet environments)
-
Install the following BitBucket Server plugin by logging into the web GUI of the Stash server and going to
Find new add-ons
.- External Hooks
- You can also install it manually by downloading the JAR file. See Installing Marketplace apps in Atlassian's web site
-
Configure the hook on your control repo.
- Click the
Hooks
tab under the repo's settings. - Click the pencil icon next to
External Post-Receive WebHooks
- Point to an executable script. For example:
-
Deploy only the
production
branch/environment:#!/usr/bin/env bash echo "Invoking a deployment from BitBucket... " curl -v -k -X POST -H 'Content-Type: application/json' \ https://puppetmaster:8170/code-manager/v1/deploys?token=`cat /var/opt/deploy_token.txt` \ -d '{"environments": ["production"], "wait": true}' | cat
-
Deploy all environments:
#!/usr/bin/env bash echo "Invoking a deployment from BitBucket... " curl -v -k -X POST -H 'Content-Type: application/json' \ https://puppetmaster:8170/code-manager/v1/deploys?token=`cat /var/opt/deploy_token.txt` \ -d '{"deploy-all": true, "wait": true}' | cat
-
- Click the
-
You will need to make sure that the BitBucket server has a deploy token avaliable at
/var/opt/deploy_token.txt
.
A Rampup BitBucket profile is available here: PuppetLabs-RampUpProgram/rampup_profile_bitbucket_server
A working Vagrant example of using Puppet Enterprise with Code Manager and Stash is avaliable here: petems/pe-bitbucket-vagrant-stack