6

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.

1
  • 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 )
    – Tensibai
    Commented Dec 21, 2017 at 13:04

2 Answers 2

3

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.

1

You can use Seed Jobs to accomplish this. Seed Jobs (which are actually freestyle jobs) are included in the Job-DSL Plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.