KSF
KSF

Reputation: 388

Trigger Jenkins Build on Perforce submit by keyword

I am wondering if anyone knows if it is possible to trigger a Jenkins build on a Perforce commit, only if it has a certain keyword in it?

My use case is that I am looking to find a way to trigger a Jenkins build that will build a Nuget package of the library I am working on, and place it in the correct Nuget server directory. I don't want to build a Nuget package each and every time I make a submit to Perforce, so I was wondering if it is possible to set up some kind of trigger to only run the Jenkins build if some keyword was included in the changelist description.

Does anyone know if this is possible, or any other possible ideas on how to implement this?

Upvotes: 2

Views: 434

Answers (1)

tkosinski
tkosinski

Reputation: 1696

This works for me. I'm sure it could be more efficient, but it works. This looks for the string "buildit" in the changelist description.

First, create a change-submit trigger in Perforce, e.g.,

buildit change-submit //... "/usr/bin/buildthis %changelist%"

(wherever you place it should be writable, and create a file called "description" that should also be writable).

Below is the contents of the buildthis script:

#!/bin/sh
changelist="$1"
P4PORT=perforce:1666
P4CLIENT=myclient
P4USER=myuser
p4 -p $P4PORT -c $P4CLIENT -u $P4USER describe $changelist >/usr/bin/description
if grep -q buildit /usr/bin/description;
    then 
        curl -X POST http://jenkinsserver:port/job/jobname/build?token=TOKEN
    else
        exit 0
fi

Upvotes: 1

Related Questions