<p>I think you're asking too many questions in one post for the StackExchange QA format, but I can address the Bitbucket-related questions.</p>

<ul>
<li>For automatically setting up jobs for each branch (and PR) in a Bitbucket project or repository, use the <a href="https://plugins.jenkins.io/cloudbees-bitbucket-branch-source/" rel="nofollow noreferrer">official Bitbucket Branch Source plugin</a>.  This will also take care of the build status aspect of your question.</li>
<li>If you are using Bitbucket Cloud, the Bitbucket Branch Source plugin will also take care of creating webhooks in order to automatically trigger builds.</li>
<li>If you are using Bitbucket Server, you will need some other way of triggering builds.  I personally use the <a href="https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket" rel="nofollow noreferrer">pull request notifier</a> plugin for Bitbucket since our workflow is PR-based, but you can use whatever plugin or tool works for you - there are a ton of them out there.</li>
</ul>

CC BY-SA 4.0
2020-05-27T17:03:05.197Z
2020-05-27T17:03:05.197Z
jayhendren
<p>I want to setup a CD system for a yocto project which is version controlled in a bitbucket repository. I want to write a bitbucket pipeline which triggers a jenkins job on a build server which starts a yocto build. The reason for this is that yocto builds can take up anywhere to 6h for complete rebuilds and thats pretty costintensive with bitbucket pipelines. My idea to test this setup was to use docker containers so I can test the whole setup locally with ngrok. There are some questions I have regarding this:</p>

<ul>
<li>does the containerized setup for this make sense?</li>
<li>can I mark a bitbucket pipeline build from the outside as in progress/completed/failed?</li>
<li>what is the nicest way to trigger a jenkins job from bitbucket pipelines? Webhooks?</li>
<li>how can I make jenkins differentiate between two branches when triggered by bitbucket pipelines?</li>
</ul>

<p>The setup I am pondering with atm are two docker containers. One is running the jenkins server and the other is the build server with a custom image, which I have verified working. I found that you can instrument multiple containers using docker-compose so I came up with this docker-compose.yml:</p>

<pre><code>version: '3'
services:
    yocto-server:
        build: .
        container_name: yocto-server
        networks:
            - build-network

    jenkins-master:
        image: jenkins/jenkins
        privileged: true
        working_dir: /home/jenkins
        depends_on:
            - yocto-server
        ports:
            - 8080:8080
        networks:
            - build-network
        links:
            - yocto-server
networks:
    build-network:
        driver: bridge
</code></pre>

<p>Can jenkins invoke a command via ssh/telnet/docker magic to the second container with this setup?
Because as I see it I have to do the following steps:</p>

<ul>
<li>mark the build in bbp as in progress</li>
<li>if repository is present in the container pull and checkout a specific branch</li>
<li>if repository is not pressent in the container clone it first
run the build with parameters provided by jenkins</li>
<li>depending on the exit code of the build flag the bbp build as completed/successfull</li>
<li>upload the artifacts to bitbucket</li>
</ul>

<p>I am very thankful for any inside on this because I have very little knowledge about docker-compose and jenkins. </p>

<p>For clarification I am using Bitbucket Cloud.</p>

<jenkins><bitbucket>
Bitbucket Pipeline & Jenkins & Yocto
Curunir
# Bitbucket Pipeline & Jenkins & Yocto

(Asked by: username_0 on 2020-05-26)

I want to setup a CD system for a yocto project which is version controlled in a bitbucket repository. I want to write a bitbucket pipeline which triggers a jenkins job on a build server which starts a yocto build. The reason for this is that yocto builds can take up anywhere to 6h for complete rebuilds and thats pretty costintensive with bitbucket pipelines. My idea to test this setup was to use docker containers so I can test the whole setup locally with ngrok. There are some questions I have regarding this:

does the containerized setup for this make sense?
can I mark a bitbucket pipeline build from the outside as in progress/completed/failed?
what is the nicest way to trigger a jenkins job from bitbucket pipelines? Webhooks?
how can I make jenkins differentiate between two branches when triggered by bitbucket pipelines?

The setup I am pondering with atm are two docker containers. One is running the jenkins server and the other is the build server with a custom image, which I have verified working. I found that you can instrument multiple containers using docker-compose so I came up with this docker-compose.yml:
version: '3'
services:
    yocto-server:
        build: .
        container_name: yocto-server
        networks:
            - build-network

    jenkins-master:
        image: jenkins/jenkins
        privileged: true
        working_dir: /home/jenkins
        depends_on:
            - yocto-server
        ports:
            - 8080:8080
        networks:
            - build-network
        links:
            - yocto-server
networks:
    build-network:
        driver: bridge

Can jenkins invoke a command via ssh/telnet/docker magic to the second container with this setup?
Because as I see it I have to do the following steps:

mark the build in bbp as in progress
if repository is present in the container pull and checkout a specific branch
if repository is not pressent in the container clone it first
run the build with parameters provided by jenkins
depending on the exit code of the build flag the bbp build as completed/successfull
upload the artifacts to bitbucket

I am very thankful for any inside on this because I have very little knowledge about docker-compose and jenkins. 
For clarification I am using Bitbucket Cloud.

**Tags:** jenkins, bitbucket


---

## 1 answers

### Answer by username_1 on 2020-05-27. Score: 1

I think you're asking too many questions in one post for the StackExchange QA format, but I can address the Bitbucket-related questions.

* For automatically setting up jobs for each branch (and PR) in a Bitbucket project or repository, use the [official Bitbucket Branch Source plugin](https://plugins.jenkins.io/cloudbees-bitbucket-branch-source/). This will also take care of the build status aspect of your question.
* If you are using Bitbucket Cloud, the Bitbucket Branch Source plugin will also take care of creating webhooks in order to automatically trigger builds.
* If you are using Bitbucket Server, you will need some other way of triggering builds. I personally use the [pull request notifier](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket) plugin for Bitbucket since our workflow is PR-based, but you can use whatever plugin or tool works for you - there are a ton of them out there.


---

