List Job Variables defined for all groups, jobs, and steps

Languages: C#, VB.NET

View on GitHub to download or comment.

See the Client API Examples Introduction for additional information and prerequisites.

Samples index

This script creates a tab-delimited file listing the Job Variables defined for all groups, jobs, and steps.

This script lists the variables explicitly defined (or overridden) at each level; it does not list inherited variables. Note that jobs may be inheriting variables defined at other levels that are not included here:

  • Server
  • Queue
  • Remote Agent

See Also

sample.cs
StringBuilder variableList=new StringBuilder();


void Main()
{
	variableList.AppendLine("Group\tJob\tStep\tVariable\tValue");
	using (var session = Scheduler.Connect(".", LoginAuthenticationType.Windows, "", ""))
	{
		using (var context = session.NewDataContext())
		{
            //fetch the root group
			var root = context.GetJobGroup(null);

			EnumerateVariables(root);
		}
	}
	
	using(var file=File.CreateText(@"d:\temp\variablelist.txt"))
	{
		file.Write(variableList);	
	}
}


void EnumerateVariables(JobGroup group)
{
	ListVariables(group, null, null, group.JobVariables);
	
    //get all jobs in the group. Use FullFetch so their variables and steps are all retrieved in a single server call
	var jobs=group.GetJobs(ObjectFetchOptions.FullFetch,false);
	foreach(var item in jobs)
	{
		EnumerateVariables(group, item);	
	}
	
    //get all the child groups. Use FullFetch so their variables and steps are all retrieved in a single server call
	var childGroups=group.GetGroups(ObjectFetchOptions.FullFetch,false);
	foreach(var item in childGroups)
	{
		EnumerateVariables(item);
	}
}

void EnumerateVariables(JobGroup group, Job job)
{
	ListVariables(group, job, null, job.JobVariables);
	
	foreach (var step in job.Steps)
	{
		ListVariables(group, job, step, step.JobVariables);
	}
}

void ListVariables(JobGroup group, Job job, JobStep step, ArcanaDevelopment.adTempus.Client.Collections.JobVariableCollection variables)
{
	foreach(var item in variables)
	{
		WriteVariable(group, job, step, item);
	}	
}

void WriteVariable(JobGroup group, Job job, JobStep step, JobVariable variable)
{
	variableList.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\r\n", group?.Name ?? "", job?.Name ?? "", step?.StepNumber.ToString() ?? "", variable.Name,variable.Value);
}
sample.vb
Private variableList As StringBuilder = New StringBuilder()
Const vbTab As Char =Microsoft.VisualBasic.Constants.vbTab

Sub Main
	
        variableList.AppendLine("Group" & vbTab & "Job" & vbTab & "Step" & vbTab & "Variable" & vbTab & "Value")

        Using session = Scheduler.Connect(".", LoginAuthenticationType.Windows, "", "")
            Using context = session.NewDataContext()
				
				        'fetch the root group
                Dim root = context.GetJobGroup(Nothing)
                EnumerateVariables(root)
            End Using
        End Using

        Using file = System.IO.File.CreateText("d:\temp\variablelist.txt")
            file.Write(variableList)
        End Using
    End Sub

    Private Sub EnumerateVariables(ByVal group As JobGroup)
        ListVariables(group, Nothing, Nothing, group.JobVariables)
		
		'get all jobs in the group. Use FullFetch so their variables and steps are all retrieved in a single server call
        Dim jobs = group.GetJobs(ObjectFetchOptions.FullFetch, False)

        For Each item In jobs
            EnumerateVariables(group, item)
        Next

		'get all the child groups. Use FullFetch so their variables and steps are all retrieved in a single server call
		Dim childGroups = group.GetGroups(ObjectFetchOptions.FullFetch, False)

        For Each item In childGroups
            EnumerateVariables(item)
        Next
    End Sub

    Private Sub EnumerateVariables(ByVal group As JobGroup, ByVal job As Job)
        ListVariables(group, job, Nothing, job.JobVariables)

        For Each item In job.Steps
            ListVariables(group, job, item , item.JobVariables)
        Next
    End Sub

    Private Sub ListVariables(ByVal group As JobGroup, ByVal job As Job, ByVal [step] As JobStep, ByVal variables As ArcanaDevelopment.adTempus.Client.Collections.JobVariableCollection)
        For Each item In variables
            WriteVariable(group, job, [step], item)
        Next
    End Sub

Private Sub WriteVariable(ByVal group As JobGroup, ByVal job As Job, ByVal [step] As JobStep, ByVal variable As JobVariable)
	variableList.AppendFormat("{0}" & vbTab & "{1}" & vbTab & "{2}" & vbTab & "{3}" & vbTab & "{4}" & vbCrLf, If(group?.Name, ""), If(job?.Name, ""), If([step]?.StepNumber.ToString(), ""), variable.Name, variable.Value)
End Sub

Comments

View on GitHub to comment.