DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Mastering Shift-Left: The Ultimate Guide to Input Validation in Jenkins Pipelines
  • Integrating Jenkins With Playwright TypeScript: A Complete Guide
  • Jenkins Pipelines With Centralized Error Codes and Fail-Fast
  • Multi-Cluster Kubernetes Sealed Secrets Management in Jenkins

Trending

  • Kubeflow: Driving Scalable and Intelligent Machine Learning Systems
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Hybrid Cloud vs Multi-Cloud: Choosing the Right Strategy for AI Scalability and Security
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Adding Version Details on MANIFEST.MF via Jenkins

Adding Version Details on MANIFEST.MF via Jenkins

By 
Amazia Gur user avatar
Amazia Gur
·
May. 05, 15 · Interview
Likes (0)
Comment
Save
Tweet
Share
17.8K Views

Join the DZone community and get the full member experience.

Join For Free

Article Purpose:

The following article will suggest a solution for adding custom information to your web application using manifest.mf file and expose that information in API.

The necessity for this solution came to solve "blindness" in deployment. in simpler words,

I want to know what war i deployed, what build version it has and more useful information i might need.

Since i exposed the information via API, this could function as application "health-check", so this is a nice little addition for the solution.

Techs:

  • war (your web application)
  • mvn - build tool
  • maven-war-plugin
  • Jenkins job

Step 1 - Adding maven war plugin

First you should add the maven war plugin to your pom.xml.

In the <manifestEntries> tag you should add the custom information you need. in case you want to use the default information the plugin gives you out of the box, just mark the value of <addDefaultImplementationEntries> as true.

In the following example you can see i added fields like buildVersion, build time and so on. This build tool is going to provide this data, in this case jenkins.

<build>
    <plugins>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
   <manifest>
    <addDefaultImplementationEntries>false</addDefaultImplementationEntries>
   </manifest>
   <archive>
    <manifestEntries>
     <Major-Version>${project.version}</Major-Version>
     <Build-Version>${build.number}</Build-Version>
     <Build-Time>${maven.build.timestamp}</Build-Time>
     <Build-Host>${agent.name}</Build-Host>
     <Build-User>${user.name}</Build-User>
    </manifestEntries>
   </archive>
  </configuration>
 </plugin>
   </plugins>
 <finalName>${[yourWarName].war.finalName}</finalName>
</build>

Step 2 - Define maven variables

The properties you want to add should be provided from "out side", you should add variables in your pom so Jenkins assign the values there.

In the following example below, you can see the build.number variable i defined in the previous step.

<build.number>SNAPSHOT</build.number>

Step 3 - Adding maven goals to your Jenkins job definitions

Jenkins has available environment variables you can pass to the maven goal,
such as BUILD_NUMBER, BUILD_ID and so on.
assign the Jenkins variable to the maven variable in the build step.
when Jenkins is going to build the code, it going to sign the manifest,mf file with the custom information we wanted.


Step 4 - Exposing the information of war

We did all this hard work for one purpose. so we will have this information available in deployment stage.

you should expose via API this information. in this example i used Spring MVC controller, and mapped the data to json format but you can have your pick.

  package your.package;

  @Controller
  @RequestMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
    public class VersionController {

 @Autowired
 ApplicationContext applicationContext;
 
 @RequestMapping(method = RequestMethod.GET)
 @ResponseBody
 public JSONObject getVersion() {
  JSONObject result = new JSONObject();
  Resource resource = applicationContext.getResource("/META-INF/MANIFEST.MF");
  
  try {
   Manifest manifest = new Manifest(resource.getInputStream());
   if (manifest != null){
    Attributes mainAttributes = manifest.getMainAttributes();
    if(mainAttributes != null){
     for (Object key : mainAttributes.keySet()) {
      result.put(key, mainAttributes.get(key));
     }
    }
   }
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
     return result;

 }

}
       

Step 5 - Enjoy :)

Jenkins (software)

Opinions expressed by DZone contributors are their own.

Related

  • Mastering Shift-Left: The Ultimate Guide to Input Validation in Jenkins Pipelines
  • Integrating Jenkins With Playwright TypeScript: A Complete Guide
  • Jenkins Pipelines With Centralized Error Codes and Fail-Fast
  • Multi-Cluster Kubernetes Sealed Secrets Management in Jenkins

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: