<p>You can use Seed Jobs to accomplish this. Seed Jobs (which are actually freestyle jobs) are included in the <a href="https://wiki.jenkins.io/display/JENKINS/Job+DSL+Plugin" rel="nofollow noreferrer">Job-DSL Plugin</a>.</p>

CC BY-SA 3.0
2017-12-21T20:49:16.177Z
2017-12-21T20:49:16.177Z
Matt O.
<p>Yes, this is pretty easy with Jenkinsfiles with no need for any third-party plugins or anything along those lines: use the <a href="https://jenkins.io/doc/pipeline/steps/pipeline-build-step/" rel="nofollow noreferrer">built-in Pipeline build step</a>.</p>

<p>I use this to trigger builds of projects in a dependency chain, so that after one project builds successfully, other projects that depend on it will pull in the updated dependency and build against it.</p>

<p>Here is what this looks like in a Jenkinsfile:</p>

<pre><code>build repoName
</code></pre>

<p>where <code>repoName</code> is a variable containing the name of the repository you wish to build.</p>

<p>Things can get a little more complicated, such as if you're using folders or Multibranch Pipelines:</p>

<pre><code>build "${projectName}/${repoName}/${branchName}"
</code></pre>

<p>This example builds a job within a Multibranch project where the variables are:</p>

<ul>
<li><code>projectName</code> - the name of my Multibranch project</li>
<li><code>repoName</code> - the name of the repository</li>
<li><code>branchName</code> - the name of the branch to build, usually <code>master</code></li>
</ul>

<p>Or this example builds a job with parameters and also triggers the build asynchronously (parent job won't wait for child job to complete before moving on to the next step):</p>

<pre><code>build(
  jobName,
  wait: false,
  parameters: [
    [
      $class: 'BooleanParameterValue',
      name: 'someBooleanParameter',
      value: true,
    ],
    [
      $class: 'StringParameterValue',
      name: 'someStringParameter',
      value: 'some string value',
    ],
  ],
)
</code></pre>

<p>As you can see, the invocation of <code>build</code> can get relatively complex.  See the documentation linked above for more complete information.</p>

CC BY-SA 3.0
2017-12-26T23:04:10.207Z
2017-12-28T18:18:18.873Z
2017-12-28T18:18:18.873Z
jayhendren
<p>Our team has two separate repositories for a frontend/backend system.  They would like to have these two repositories deployed to the shared team environment together.  </p>

<p>My understanding of the JenkinsFile is that it will only work on the repository it committed to and only run when the SCM system sends a request to Jenkins informing it of new changes.  </p>

<p>Is it possible to have the JenkinsFile in the two separate repositories communicate with each other so that when one is built the other is built as well and only after both are built, they will then be deployed?</p>

<p>My main goal here is to avoid creating a separate Jenkins job within the Jenkins UI.</p>

CC BY-SA 3.0
2017-12-21T13:04:56.690Z
As far as I know a Jenkinsfile can trigger a build, it may be another project build, so each project could trigger the other project build step before deploying I think. (I could be wrong here, not working with Jenkinsfile )
Tensibai
<jenkins-pipeline>
Is it possible to use a JenkinsFile in one repo to build and deploy a related repo?
avi
# Is it possible to use a JenkinsFile in one repo to build and deploy a related repo?

(Asked by: username_0 on 2017-12-21)

Our team has two separate repositories for a frontend/backend system. They would like to have these two repositories deployed to the shared team environment together.

My understanding of the JenkinsFile is that it will only work on the repository it committed to and only run when the SCM system sends a request to Jenkins informing it of new changes.

Is it possible to have the JenkinsFile in the two separate repositories communicate with each other so that when one is built the other is built as well and only after both are built, they will then be deployed?

My main goal here is to avoid creating a separate Jenkins job within the Jenkins UI.

**Tags:** jenkins-pipeline

> **Comments:**
> **username_1**: As far as I know a Jenkinsfile can trigger a build, it may be another project build, so each project could trigger the other project build step before deploying I think. (I could be wrong here, not working with Jenkinsfile )  

---

## 2 answers

### Answer by username_3 on 2017-12-26. Score: 3 | Accepted answer

Yes, this is pretty easy with Jenkinsfiles with no need for any third-party plugins or anything along those lines: use the built-in Pipeline build step.
I use this to trigger builds of projects in a dependency chain, so that after one project builds successfully, other projects that depend on it will pull in the updated dependency and build against it.
Here is what this looks like in a Jenkinsfile:
build repoName

where repoName is a variable containing the name of the repository you wish to build.
Things can get a little more complicated, such as if you're using folders or Multibranch Pipelines:
build "${projectName}/${repoName}/${branchName}"

This example builds a job within a Multibranch project where the variables are:

projectName - the name of my Multibranch project
repoName - the name of the repository
branchName - the name of the branch to build, usually master

Or this example builds a job with parameters and also triggers the build asynchronously (parent job won't wait for child job to complete before moving on to the next step):
build(
  jobName,
  wait: false,
  parameters: [
    [
      $class: 'BooleanParameterValue',
      name: 'someBooleanParameter',
      value: true,
    ],
    [
      $class: 'StringParameterValue',
      name: 'someStringParameter',
      value: 'some string value',
    ],
  ],
)

As you can see, the invocation of build can get relatively complex.  See the documentation linked above for more complete information.


---

### Answer by username_2 on 2017-12-21. Score: 1

You can use Seed Jobs to accomplish this. Seed Jobs (which are actually freestyle jobs) are included in the [Job-DSL Plugin](https://wiki.jenkins.io/display/JENKINS/Job+DSL+Plugin).


---

