none
Job ID inside Runbook

    Question

  • Hello,

    When a runbook is invoked it's given a Job ID. This Job ID is returned when invoking the runbook over the REST API.

    The Id I'm looking for can also be located in the view Microsoft.SystemCenter.Orchestrator.Runtime.Jobs -> Id column.

    Is there any way to detect the current Job ID inside the runbook? I can't find this value in the "Common Published Data". I guess I could use a query against the view and select the Id based on some input, but I'm not too happy with that approach.

    Any good ways of finding out the Job ID?

    Thanks!
    B

    Thursday, April 25, 2013 6:28 PM

Answers

  • I do this for logging purposes by doing a database querying within the runbook itself.  Below is the query I use.

    SELECT     POLICYINSTANCES.JobID
    FROM         POLICYINSTANCES INNER JOIN
                          ACTIONSERVERS ON POLICYINSTANCES.ActionServer = ACTIONSERVERS.UniqueID
    WHERE     (POLICYINSTANCES.ProcessID = <Activity process ID from "Initialize Data">) AND (ACTIONSERVERS.Computer = '<Runbook Server name from "Initialize Data">') AND (POLICYINSTANCES.Status IS NULL)

    Vaughn

    • Marked as answer by iambendik Thursday, April 25, 2013 8:36 PM
    Thursday, April 25, 2013 7:52 PM

All replies

  • I do this for logging purposes by doing a database querying within the runbook itself.  Below is the query I use.

    SELECT     POLICYINSTANCES.JobID
    FROM         POLICYINSTANCES INNER JOIN
                          ACTIONSERVERS ON POLICYINSTANCES.ActionServer = ACTIONSERVERS.UniqueID
    WHERE     (POLICYINSTANCES.ProcessID = <Activity process ID from "Initialize Data">) AND (ACTIONSERVERS.Computer = '<Runbook Server name from "Initialize Data">') AND (POLICYINSTANCES.Status IS NULL)

    Vaughn

    • Marked as answer by iambendik Thursday, April 25, 2013 8:36 PM
    Thursday, April 25, 2013 7:52 PM
  • A lot better than the SQL I was working on. Thank you! :) I scratched my head why it didn't work at first, but then I figured out I was in the Runbook Tester. Doh.

    Thanks again!

    Thursday, April 25, 2013 8:36 PM
  • I can get the SQL that Vaughn gave to work for getting the JobID as well, but only when running the runbook and not in the Runbook Tester.  Do you happen to know why you can't get this information when you are using the Runbook Tester?  Also, is there a way to get that information with the Runbook Tester?

    I'd like to get this information when I'm testing my runbooks as well instead of having to disable them to test the functionality.  I'm wanting to use the JobID and other information for logging purposes as well.

    Thanks!


    • Edited by gameb0y1 Wednesday, November 09, 2016 9:22 PM
    Wednesday, November 09, 2016 9:21 PM
  • JobIDs are not used by the runbook tester because the jobs are not published to the back end database to be picked up by a runbook server.  With the runbook tester the runbook executes locally on the computer where the runbook designer is executed. 

    What you can do is enable logging on the runbook and execute the runbook normally so that the server executes it rather than running it through the runbook tester.

    Vaughn

    Wednesday, November 09, 2016 9:29 PM