# Disable SCMTrigger(s) in a pipeline job with a system property

**URL:** <https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778>\
**Category:** Using Jenkins\
**Tags:** question, jenkins-test-harness\
**Created:** [May 6, 2025, 1:16pm UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778 "2025-05-06T13:16:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LoremIpsum-42](https://avatars.discourse-cdn.com/v4/letter/l/3da27b/32.png) [@LoremIpsum-42](https://community.jenkins.io/u/LoremIpsum-42)\
**Post date:** [May 6, 2025, 1:16pm UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778/1 "2025-05-06T13:16:49Z")

</div>

Hi,

I am using jenkins-test-harness and to omit the scm scanning / triggering in the test case I can set:

`jenkins.branch.MultiBranchProject.fireSCMSourceBuildsAfterSave` to `false`, see [0].

I would like to do the same for standard pipeline job definitions, to omit the SCMTrigger in the test case (I don’t want to modify the pipeline DSL definition itself - just to disable the trigger like for the multibranch pipeline).

I had a look in [0] but did not find a property - did I miss it - is it maybe undocumented, anyone an idea?

Thanks.

[0] [Jenkins Features Controlled with System Properties](https://www.jenkins.io/doc/book/managing/system-properties/)

---

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [May 6, 2025, 3:30pm UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778/2 "2025-05-06T15:30:51Z")

</div>

Maybe calling `yourjob.setTriggers([])` ([API reference](https://javadoc.jenkins.io/plugin/workflow-job/org/jenkinsci/plugins/workflow/job/WorkflowJob.html#setTriggers(java.util.List))) immediately once the job gets created might help?  
I don’t think regular pipelines have the same “_scan SCM changes immediately upon XML reload/save_” behavior as multibranch ones do, so just nuking the triggers after a successful deployment sounds like a reasonable approach to me.

* * *

On unrelated note: thank you _so_ much for the linked property! Jenkins running the scans upon CASC redeployments (and consequently rebuilding multibranch jobs configured with “_merge PR with target branch_”) have been plaguing us for quite some time. I believe this might a solution for us

---

<div class="post-metadata">

**Author:** ![LoremIpsum-42](https://avatars.discourse-cdn.com/v4/letter/l/3da27b/32.png) [@LoremIpsum-42](https://community.jenkins.io/u/LoremIpsum-42)\
**Post date:** [May 7, 2025, 7:23am UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778/3 "2025-05-07T07:23:06Z")

</div>

I don’t have the Job in my hand, they are created by the Job-DSL test(s) - so I am unable to modify them, a property to disable the trigger like you can do for the MultibranchPipeline DSL tests would be nice.  
The code just has this:

```auto
    @Unroll
	def 'test script #file.parentFile.name / #file.name'(File file) {
		given:
		def jobManagement = new JenkinsJobManagement(System.out, [:], new File('.'))

		when:
		new DslScriptLoader(jobManagement).runScript(file.text)

		then:
		noExceptionThrown()

		where:
		file << new FileNameFinder().getFileNames('src/main/groovy', '**/*.groovy').collect { new File(it) }
	}

```

On the unrelated note: Your welcome 😉

---

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [May 7, 2025, 8:56am UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778/4 "2025-05-07T08:56:11Z")

</div>

> [@LoremIpsum-42](#):
>
> a property to disable the trigger like you can do for the MultibranchPipeline DSL tests would be nice

I am unsure if it exists 🤷

> [@LoremIpsum-42](#):
>
> I don’t have the Job in my hand, they are created by the Job-DSL

From what I see in the plugin code:

- `DslScriptLoader` extends `AbstractDslScriptLoader<JobParent, GeneratedItems>`
- `AbstractDslScriptLoader`’s `runScripts()` [returns](https://github.com/jenkinsci/job-dsl-plugin/blob/6d13b4d1b7f6a856b67ff3452a9d94b63321a999/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/AbstractDslScriptLoader.groovy#L40-L41) an instance of generic type `G`
- The class itself [has](https://github.com/jenkinsci/job-dsl-plugin/blob/6d13b4d1b7f6a856b67ff3452a9d94b63321a999/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/AbstractDslScriptLoader.groovy#L15) `<S extends JobParent, G extends GeneratedItems>`
- `GeneratedItems` [has](https://github.com/jenkinsci/job-dsl-plugin/blob/6d13b4d1b7f6a856b67ff3452a9d94b63321a999/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/GeneratedItems.groovy) `final Set<GeneratedJob> jobs`
- `GeneratedJob` unfortunately [only stores](https://github.com/jenkinsci/job-dsl-plugin/blob/6d13b4d1b7f6a856b67ff3452a9d94b63321a999/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/GeneratedJob.groovy#L3-L5) `jobName` string
- But `JenkinsRule` (you should have one since you’re using Harness) has `jenkins` [public field](https://github.com/jenkinsci/jenkins-test-harness/blob/d834f3bbda264c04f91eeac887ca219d3407963f/src/main/java/org/jvnet/hudson/test/JenkinsRule.java#L271)
- `Jenkins` in turn can [get items by name](https://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#getItem(java.lang.String))
- And finally `WorkflowJob` – which defines a pipeline – [implements](https://javadoc.jenkins.io/plugin/workflow-job/org/jenkinsci/plugins/workflow/job/WorkflowJob.html) the `TopLevelItem` returned by `getItme()`

So I believe your code can be transformed to this (pseudocode, not tested):

```auto
		when:
		new DslScriptLoader(jobManagement).runScript(file.text)
		    .jobs.collect { it.jobName }
		    .collect {
		        jenkinsRule.jenkins.getItem(it) as WorkflowJob
		    }
		    .each { it.setTriggers([]) }

		then:
		noExceptionThrown()

```

Messy, but I could not think of a better solution assuming we did not find any property to handle this.  
You might want to extract all this into a helper function to be used across test classes and methods.

---

<div class="post-metadata">

**Author:** ![LoremIpsum-42](https://avatars.discourse-cdn.com/v4/letter/l/3da27b/32.png) [@LoremIpsum-42](https://community.jenkins.io/u/LoremIpsum-42)\
**Post date:** [May 7, 2025, 9:23am UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778/5 "2025-05-07T09:23:35Z")

</div>

Nice idea, could try that - but that would all happen _after_ runScript already ran and the Trigger could have “triggered” already, right?  
But I may have another idea, looking at `ScmTrigger` it asks `SCMDecisionHandler` for a decision on polling for changes - so in theory, I could just write a handler which does:

```auto
    @Override
	public boolean shouldPoll(@NonNull Item item) {
		return false;
	}

```

And it should never poll anything and trigger a build from that - I need to find time to setup [0], build an extension just for my testcase with that Handler and it should work - untested yet though.

Update: Did test it, works like expected.

[0] [GitHub - jenkinsci/gradle-jpi-plugin: Build Jenkins Plugins with Gradle](https://github.com/jenkinsci/gradle-jpi-plugin)

---

<div class="post-metadata">

**Author:** ![LoremIpsum-42](https://avatars.discourse-cdn.com/v4/letter/l/3da27b/32.png) [@LoremIpsum-42](https://community.jenkins.io/u/LoremIpsum-42)\
**Post date:** [May 7, 2025, 11:34am UTC](https://community.jenkins.io/t/disable-scmtrigger-s-in-a-pipeline-job-with-a-system-property/30778/6 "2025-05-07T11:34:28Z")

</div>

I had to confirm that theory and I can confirm, that just works like expected. Thanks @Artalus for the push to dig through the code again 😉 .
