Job Tags


A job tag identifies similar jobs or job templates, and can be used to easily search and filter jobs and job templates.

Creating a job with tags

To specify tags for a streamsets.sdk.sch_models.Job instance at creation time, you need to supply the desired tags at the time streamsets.sdk.sch_models.JobBuilder.build() is called for the pipeline being created:

job_builder = sch.get_job_builder()
pipeline = sch.pipelines.get(id=<pipeline id>)
# Create a list of tags to supply to the builder
tags = ['test/dev', 'test']
job = job_builder.build(job_name='Test job with tags', pipeline=pipeline, tags=tags)
sch.add_job(job)
job.tags

Output:

# job.tags
[<Tag (tag=test/dev)>,
 <Tag (tag=test)>]

Fetching jobs using job tag

Job tags can be used to search and filter through the available jobs and job templates on Control Hub:

sch.jobs.get_all(job_tag='test:admin')

Output:

[<Job (job_id=93084250-ef6f-4c0a-b6f8-aff54f905739:admin, job_name=Test job with tags)>]

Adding tags to an existing job

You can also add new tags to a streamsets.sdk.sch_models.Job instance via the streamsets.sdk.sch_models.Job.add_tag() method by passing in one or more string objects to add:

job = sch.job.get(job_id=<job_id>)
job.add_tag('prod/dev', 'prod')
sch.update_job(job)
job.tags

Output:

# job.tags
[<Tag (tag=test/dev)>,
 <Tag (tag=test)>,
 <Tag (tag=prod/dev)>,
 <Tag (tag=prod)>]

Removing existing tags for a job

Existing tags can also be removed from a streamsets.sdk.sch_models.Job instance via the streamsets.sdk.sch_models.Job.remove_tag() method by passing in one or more string objects to remove:

job = sch.job.get(job_id=<job_id>)
job.remove_tag('test', 'test/dev')
sch.update_job(job)
job.tags

Output:

# job.tags
[<Tag (tag=prod/dev)>,
 <Tag (tag=prod)>]]