Tutorial: Bamboo Java Specs stored in Bitbucket Server

 This guide will show you how you can store Bamboo Specs in a Git repository on Bitbucket Data Center and Server. This approach lets you automatically build and execute Bamboo Specs on every push you make to a Git repository.

はじめる前に

Step 1: Create a Git repository in Bitbucket Sever and clone it locally

  1. In Bitbucket Data Center and Server, open the Projects page.
  2. [プロジェクトの作成] を選択します。 
  3. Enter Bamboo for project name and key and select Create project.
  4. Select Create repository.
  5. Give your new repository the name tutorial and select Create repository.

You've just created a new empty repository. Use the git clone command to create a clone on your computer. For example:

git clone http://admin@localhost:7990/scm/bamboo/tutorial.git
cd tutorial
echo "Hello Bamboo Specs" > greet.txt
git add greet.txt
git commit -m "Setup master branch"
git push



Step 2: Create a linked repository in Bamboo

  1. Open Bamboo and go to cogwheel icon > Linked repositories
  2. Select Add repository.
  3. Select a Bitbucket Server/Stash repository type.
  4. Select a name for your repository.
  5. From the Server dropdown, select your Bitbucket Data Center and Server.
  6. In the Web repository section, select the Bamboo / tutorial repository from the Web repository drop-down. 
  7. Select Save repository.

Your new repository is created and you can start using it in Bamboo.



Step 3: Enable processing of Bamboo Specs in your repository

 By default, Bamboo won't look for Bamboo Specs in the Git repository until you explicitly tell it to do so. Let's do it now:

  1. Go to cogwheel icon > Linked repositories
  2. Select your repository. 

  3. In the Bamboo Specs tab, enable Scan for Bamboo Specs.

In this tutorial we simply grant access to all projects in the Bamboo instance. You can fine-tune project access. See Enabling repository-stored Bamboo Specs.

Now, Bamboo is ready to execute Bamboo Specs when the relevant code it committed to the repository. Let's create some code.

Step 4: Create Bamboo Specs project using Maven

  1. Go to the empty Git repository you cloned in step 1:

    cd tutorial
  2. Use the Maven archetype to create a project template. For the purpose of this tutorial, type:
    Note: You must create Bamboo Specs in the bamboo-specs directory, under the repository root.

    mvn archetype:generate -B \
      -DarchetypeGroupId=com.atlassian.bamboo -DarchetypeArtifactId=bamboo-specs-archetype \
      -DarchetypeVersion=6.2.1 \
      -DgroupId=com.my.company -DartifactId=bamboo-specs \
      -Dversion=1.0.0-SNAPSHOT -Dpackage=com.my.company

    ここで:

    プロパティ説明
    archetypeGroupIdBamboo Specs archetype’s groupId. Must be set to com.atlassian.bamboo
    archetypeArtifactIdBamboo Specs archetype’s artifactId. Must be set to bamboo-specs-archetype
    archetypeVersionBamboo Specs archetype’s version. It should match the version of Bamboo you’re using.
    groupIdID of the project’s group (eg. base name of your company); it can have an arbitrary value.
    artifactIdID of the project’s artifact; it should be set to bamboo-specs, so the project will be created in the bamboo-specs directory; you can change this value, but then you must manually rename the output directory to bamboo-specs.
    versionThe version of your project; it can have an arbitrary value.
    packageThe prefix of the Java package that you want to use for the project.

Your project is created. You can open it in an IDE, such as Eclipse or IDEA, if you want to see how the project is set up. For more information on the code structure, take a look at our tutorial: Create a simple plan with Bamboo Specs.

Step 5: Commit and push code changes to Bitbucket Data Center and Server

  1. Create a new project in Bamboo with the name "Project Name" and key "PRJ".
  2. Go to Project settings > Bamboo Specs repositories and select the linked repository created in Step 2.
  3. Add created bamboo-specs directory to VCS and push changes to the server:

    git add bamboo-specs
    git commit -m "Initial commit of Bamboo Specs"
    git push

As soon as you push your code changes to Bitbucket Data Center and Server, Bamboo will get notified about a new commit available.

Bamboo will checkout your project, compile it, and execute Bamboo Specs in a sandbox environment.

Execution of Bamboo Specs will create or update configuration of plans or deployment projects accordingly. 

Step 6: Check to see if the plan was created

  1. Open your Bamboo instance.
  2. From the header, select Build > All build plans
  3. Open the project and plan you've just created.

    All configuration options are disabled because entire plan configuration is now managed by Bamboo Specs from your Bitbucket repository. 

  4. Select Run plan to execute the build.

  5. Find the "Hello World!" message in the logs. 

    Regardless whether your Bamboo Specs were processed successfully or not, you'll receive an email with status of you your Bamboo Specs execution.

次のステップ

 Here are some resources that can help you with writing your own Bamboo Specs:

最終更新日: 2023 年 10 月 10 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.