MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Continuous Build Integration using Perforce and Hudson

scmuser created the topic: Continuous Build Integration using Perforce and Hu
Continuous Build Integration using Perforce and Hudson

A little background

The basic premise of Continuous Build Integration is simple. You want to know, as soon as possible, whether the the code that you just checked into the source control is breaking anything or not. So, as soon as you checkin your code, the build server gets all your latest code and all other code that depends on your code and builds all the affected projects. Compilation error or failure of any of the test cases should raise an alarm (i.e. send an email to the group).

We are using Perforce as the source control and Hudson as our build server. All of our projects are Mavenized. We have set up a trigger on our Depo in Perforce such that whenever anything is committed to our Depo, it makes an HTTP request with parameters such as the changelist number, clientspec, and userid.

When I joined this project, I inherited a small but a very smartly written servlet that handled the HTTP requests made by Perforce upon any commit. This servlet would:

1. get the changelist number (from the HTTP parameters)
2. get the list of files committed under that changelist by executing the perforce client (p4.exe): p4.exe -p p4server:port -u p4userid -P p4passwd fstat @1234,@1234
3. Identify the projects affected by these files, and
4. Kickoff Hudson build projects to do the build(s).

The catch was that this small code was written in Groovy (apparantly, it was small because it was written in Groovy) and nobody knew Groovy in our team. All of our projects are in Java and it doesn’t make sense to add a completely new programming language to the mix just to save a about 50 lines of code, when there is 1000s of lines of Java code base lying around. So we wanted to convert this Groovy servlet into Java.

This post is about the problem that I faced in step 2 above (retrieving file names committed under a given change list id).

The problem

Even after setting the userid and password flags ( -u and -P) while calling p4.exe and even after setting P4USER and P4PASSWD environment variable, Perforce would not return any data. It would just send back an error message saying: “P4PASSWD is wrong or is unset.”

As it turns out, for some reason, you need first execute p4 login command before calling the p4 fstat command. And p4 client does not accept the password provide in the -P flag or P4PASSWD env variable. When you call p4 login, it asks for the password and waits on the stdin for the user to enter the password. Obviously, this is no good for the continuous build integration. This process must execute without any manual intervention.

The solution

The following is the code snippet that did the trick for me.

//the following code is executed once to login
StringBuilder sb = new StringBuilder();
String loginCmd = "p4 -u " + this.userid + " -P " + this.passwd + " -p " + this.host + " login";

Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(loginCmd);
OutputStream os = p.getOutputStream();
os.write(this.passwd.getBytes());
os.write(“\r\n”.getBytes());
os.flush();
int returncode = p.waitFor();
getOutput(stringBuilder, p.getInputStream());

if (returncode != 0) {
throw new Exception(“Problem in login. Return code: ” + returncode + ” Output:” + sb);
}

…..
//In another method that gets the fstat output for a given changelist
Runtime runtime = Runtime.getRuntime();
String fstatCmd = “p4 fstat @” + changeListId + “,@” + changeListId;
Process p = runtime.exec(fstatCmd);
getOutput(sb, p.getInputStream());
int returncode = p.waitFor();
if (returncode != 0) {
throw new Exception(“Problem in running fstat. Return code: ” + returncode + ” Output:” + sb);
}

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Advice on our Hudson setup / How to Poll Dependencies

scmuser created the topic: Advice on our Hudson setup / How to poll dependenc Advice on our Hudson setup / How to poll dependencies Hi, I’m looking…

Read More

Hudson CI for TFS projects?

pankaj2252369@gmail.com created the topic: Hudson CI for TFS projects? Does any one had experience on HUDSON & TFS Integration? more light would be helpful. rajeshkumar replied the…

Read More

DevOps Lifecycle Explained With Real-World Examples: A Complete Beginner’s Guide

Introduction Software development has changed a lot over the past few years. Businesses no longer want to wait several months for a software update. Customers expect websites,…

Read More

List of Top Free Open Source & Self Hosted Application for Software Development – Continuous Integration & Deployment

This page lists free, open source CI/CD servers you can host yourself, from long-established tools such as Jenkins, GitLab CI, GoCD and Buildbot to lighter, container-native options…

Read More

How to Install Helix Core (Perforce Server)

To install Helix Core (the Perforce server, p4d) on Ubuntu, add the official Perforce APT repository and install the helix-p4d package. Then run the bundled configure-helix-p4d.sh script…

Read More

DevOps vs Traditional IT Operations: 10 Key Differences Explained

Introduction Information technology has changed how businesses develop, deliver, and manage software. Earlier, most organizations followed traditional IT operations. Development teams created applications, testing teams checked their…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x