Configuring Jenkins Build Jobs

In this section, we cover how to configure an automated build job in Jenkins, this will perform the following steps:

  • Periodically poll our source code repository for new code commits.
  • On detection of a new code commit, initiate Maven to build and package the code.
  • Publish the packaged code (or artifact) to a Software Repository, such as Artifactory, Nexus or Archiva.
  • Register the artifact with MyST.

Prerequisites

Before performing a SOA, OSB or ADF build it assumed that:

  1. the Oracle products are installed on our CI server and
  2. the local or remote Maven Repository used by the CI server has been pre-seeded with the required Oracle Maven dependencies as described in Configuring Maven Builds.

Setup global variables in Jenkins

To simplify the on-going configuration of jobs in Jenkins, we recommend defining a couple of global properties. Log into the Jenkins console, click on Manage Jenkins and select Configure System.

Locate the Global properties section and click on the Environment variables checkbox if not already selected. Then click Add to add the following variables.

  • MAVEN_REPO_URL - This is the URL of the Software Repository (such as Artifactory, Nexus or Archiva) that we will publish our built artifacts to.

  • FMW_HOME - The location of the Oracle Fusion Middleware Oracle Home where the Oracle Middleware is installed.

Click Save. We will re-use these variables later in our automated jobs.

Create Automated Build Job

From within the Jenkins console, click on New Item. In Item Name enter an appropriate name for our Maven build job. Next select Maven project as job type.

Click OK.

Specify Source Code Location

Under Source Code Management select your source code repository type (such as Subversion or Git). For the URL, enter the full path to the JDeveloper project directory in our source code repository.

We can leave all the other fields with default values.

When checking out an Oracle OSB project we need to specify the project's parent directory, this is due to a constraint with the Oracle OSB Maven build which needs to take the deployment URI from the parent directory.

This means, when Jenkins checks out the project, by default it will look for the POM file in the parent directory, so we need to specify the relative path to the POM file in the project sub-directory.

Configure Build Triggers

Under Build Triggers tick Poll SCM and enter the schedule, for example, a schedule of H/10 * * * * means to poll every ten minutes.

Add Pre-Build Step

Click on Add pre-build step and then select Invoke top-level Maven targets

Select Maven as the Maven Version and enter the following into the Goals field:

build-helper:parse-version versions:set '-DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}-${BUILD_NUMBER}'

This tells Maven to always append the build number to the artifact version.

Click on Advanced... below the step. For POM specify the location of the pom.xml file relative to the URL we set under Source Code Management.

Normally this will be just pom.xml, but in the case of OSB projects, we need to specify this in the format <osb_project-dir>/pom.xml

Configure Build Step

Go to the Build section. For the Root POM specify the location of the pom.xml file relative to the URL we set under Source Code Management.

Normally this will be just pom.xml, but in the case of OSB projects, we need to specify this in the format <osb_project-dir>/pom.xml

For the Goals and options field enter clean package -DoracleHome=$FMW_HOME.

Click Save. This will take us to the main job screen for our newly created job.

Execute Build Job

To test that the job is executing correctly, either wait for Jenkins to initiate the job according to the specified schedule or click Build Now to manually trigger the job.

This will take us back to the main job screen. Once initiated, click on the progress bar to see the Console Output.

The first time Jenkins executes a build job for a particular component type, Maven has to download all of the build dependencies, as a result the initial execution can take a while, future builds should be significantly faster.

Update Build Job to Publish to Artifactory

Once our build job is performing as expected, we need to modify it to publish the built artifact to our software repository.

From the main screen for our build job, click Configure to return to the configuration screen.

Navigate to the Build section and add the following to the end of the Goals and options field:

install:install deploy:deploy - DaltDeploymentRepository=central::default::$MAVEN_REPO_URL

Update Build Job to Register Artifact with MyST Studio

Once our build job is performing as expected, we need to modify it to register the built artifact with MyST.

From the main screen for our build job, click Configure to return to the configuration screen.

Navigate to the Post-build Actions section at the bottom of the page. Click on Add post-build action and then select Publish to MyST Studio.

Make sure the Active box is ticked.

Click Save to save our changes and return from to main job screen within Jenkins.

Validate Registration with MyST

Click Build Now to manually trigger the job. Click on the progress bar for the job that appears in the Build History and go to the Console Output.

Once the job completes, at the end of the output we should see output similar to the following

{
  "buildNumber": "3",
  "startTime": "2016.06.09 at 04:24:45 UTC",
  "endTime": "2016.06.09 at 04:25:32 UTC",
  "status": "SUCCESS",
  "component": {
    "componentType": "ofmw-osb",
    "description": "",
    "mavenModel": {
      "groupId": "com.acme",
      "artifactId": "StockServices"
    },
    "binaryVersion": "1.0-3",
    "managedBy": "CI_SERVER",
    "buildStatus": "BUILT",
    "metadata": {
      "artifact.repository.type": "sbar"
    },
    "name": "StockServices",
    "topLevel": true
  },
  "scmState": {
    "url": "svn://vrepo.testdrive.fusioncloud.com/repos/code/trunk/12.2.1/Stock/src/osb",
    "branch": "NA",
    "commit": "3"
  }
}

Your artifact has now been published to MyST Studio. See section Artifact Management for details on how to view this artifact in MyST Studio.

results matching ""

    No results matching ""