Jump to content

Adding a trigger using command line


  • Please log in to reply
3 replies to this topic

#1 Nicolas



  • Members
  • Pip
  • 8 posts

Posted 13 February 2015 - 09:43 AM

Hi there.
So I'm using Perforce in conjonction with Jenkins, and I use p4triggers to trigger a Jenkins build. Triggers look like that
UPWSP change-commit //depot/up/valiconnect/current/... "wget --auth-no-challenge --http-user=jenkins --http-password=password --secure-protocol=TLSv1 http://jenkins/job/UPWSP/build?token=perforce"

I'm in charge of Jenkins, and I'm creating every job needed for the dev team. I would like to automate the creation of jobs concerning Perforce branch of existing projects.

I'm close  to do it, but I need to add a triggers via command line, and I don't know how to do it. I used to create triggers with


p4 triggers
, but in command line (even with -o) it doesn't work.
Any idea?
Thank you

#2 P4Gronk



  • Members
  • Pip
  • 1 posts

Posted 13 February 2015 - 10:07 AM

Hi Nicolas,

one way it can be done is by getting the existing trigger table into a temp file and add the line you need to it. You can then pipe that into p4 again.

p4 -p <p4port> -u <user> + " triggers -o > triggers
echo ' trigger.name trigger_type //some/depot/path/... \"/path/to/trigger.sh ...other_stuff..."' >> triggers
cat triggers | p4 -p <p4port> -u <user> + " triggers -i

That works in bash for me. Please make sure to indent the string and note the -i parameter to the p4 triggers call that will make p4 read the trigger spec from stdin.


#3 ThatGuy


    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 13 February 2015 - 10:27 AM

Hi Nicholas,

Here are the steps you should take to automate the updating of the triggers table in a script or through a Jenkins job.

You should first do p4 triggers -o to pipe out the current triggers table to a text file (or string if you are within the context of a script). This is also a good idea because you get to save a copy of the current triggers table before updating it.

e.g. p4 triggers -o > triggers.txt

You should then append the new trigger you want to add to the EOF of the triggers.txt file that you've just created.

echo UPWSP change-commit //depot/up/valiconnect/current/... "wget --auth-no-challenge --http-user=jenkins --http-password=password --secure-protocol=TLSv1 http://jenkins/job/U...token=perforce" >> triggers.txt

After this you can update the triggers table with this command.

type p4 triggers -i | triggers.txt

These commands will work on Windows but if you are on a Linux machine use the equivalent Linux commands such as cat instead of type.


Certified P4.

#4 Nicolas



  • Members
  • Pip
  • 8 posts

Posted 13 February 2015 - 10:46 AM

Will try that, thanks for the fast answer

Also tagged with one or more of these keywords: trigger

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users