determine if editor script is running headless or interactively

I have an editor script which executes both while running interactively (eg in editor) and when running headless (eg doing a build on jenkins).

i would like the behavior in these two scenarios to be different.
is this possible to determine during runtime in some nice manner,
or do i need to pass in an environment variable or similar ?

Quite old question, but for others to come: The variable you are searching for is Application.isBatchMode: Unity - Scripting API: Application.isBatchMode

Example:

if (Application.isBatchMode)
{
    Debug.Log("Running in headless mode");
}
else
{
    Debug.Log("Running in interactive mode");
}