Understanding Custom triggers

mconners
Valued Contributor

Hello Everyone,

Please excuse me for this as I know this has been talked about before on JAMF Nation. However, every time I search for this subject, I find articles that get me more confused.

We have a few policies that seem to be jumping on top of each other, even running before I want them to be run. With a custom trigger, we would have more control of WHEN a policy would be run.

Could someone point me to or reply back on how to use a custom trigger? For instance, how would I set up policy 1 to run in position 1 and a 2nd policy to be triggered from the completion of policy 1.

I don't know the syntax or how this is configured so I get that second policy to run WHEN policy 1 is completed. I know I have to enter in something in policy 1 and then set policy 2 to have a custom trigger, I just don't how to configure policy 1 and policy 2.

Thank you!

7 REPLIES 7

mm2270
Legendary Contributor III

@mconners There are really several ways to approach this. At it's simplest, you could do something as basic as adding something like the following into the Files and Processes > Execute Command field in Policy 1

/usr/local/bin/jamf policy -trigger <triggername>

That would execute the specific policy called by that trigger at the very end of the Policy 1 run. However, that doesn't have any actual logic to it, meaning, even if Policy 1 fails, it will try to run the policy called by the trigger. If you have some dependencies there, meaning Policy 1 must execute successfully before Policy 2 should run, then you'd want to do this in a script running as "After" instead, and within the script, add some logic to check for whatever it is that Policy 1 should have done, and if the result is true/successful, call the next policy. I can't necessary guide you specifically on that, because it all depends on what your policies are doing, and how to check for the success status, and indeed, whether that's even important.
I'm thinking the latter example is likely how a lot of people are using custom triggers when talking about chaining multiple policies together.

You can also just call a policy by it's trigger on the command line with the same command above. This can be useful when you don't want to put something in Self Service, but still want an easy way to call the policy on a scoped system in a manual way, rather than waiting for a check-in or other condition to occur. I have a few policies set up this way. They have no direct trigger executing them, are scoped to all systems, or just systems within a Smart Group, are usually set to an Ongoing frequency, and I can call them when working on a machine from Terminal whenever I need to.

Hope that helps clarify things a bit. Post back if you still have any questions.

alexjdale
Valued Contributor III

Yeah, I strongly recommend using "control scripts" with logic that calls various policy triggers when you need to control the timing of events. Once you get the hang of it, it's very effective.

mconners
Valued Contributor

Thank you both for your quick replies. This does make sense now.

Without being a scripter, I need to learn about how to determine these dependencies. I can totally see how this would be beneficial and something we need to learn to do.

This is guiding me along, thank you.

rderewianko
Valued Contributor II

That being said, jamf is also preferring you use the "event" command instead of trigger

jamf policy -event <yourtriggerhere>

mm2270
Legendary Contributor III

@rderewianko Yeah, I have a hard time shedding the older -trigger in favor of the new -event Fortunately, for now at least, both still work. Not sure if -trigger will eventually be deprecated.

rderewianko
Valued Contributor II

@mm2270 me too.. I've alway wondered the reasoning for working on a change.

Look
Valued Contributor III

I just have one policy with a simple script that calls other policies directly by their triggers as specified in arguments 4 thru 11 (the ones you can populate in a policy in JAMF).
You just queue up the triggers in the scripts options with the triggers you want in the order you want.

#!/bin/bash
echo START
date
for Custom_Policy in $(seq 4 11); do
if [[ "${!Custom_Policy}" ]]; then
echo Running trigger ${!Custom_Policy}
jamf policy -event "${!Custom_Policy}"
fi
done
echo FINISH
date