How to enable "Trigger builds remotely (e.g., from scripts)" in scripted pipeline job?

Hello,

I am getting the below error when trying to use the pipelineTriggers property “$class: ‘RemoteBuildTrigger’” in the scripted pipeline job in the following code.

I am using [Jenkins 2.346.2].

Can someone please help me to resolve this error?

timestamps {
  node() {
    properties([
      pipelineTriggers([
            [$class: 'RemoteBuildTrigger', remoteBuildToken: 'XXXXX']      
      ]),
      disableConcurrentBuilds(), 
      [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: true], 
      parameters([
        string(
          defaultValue: '',
          description: '',
          name: 'Repo URL'
        )   
      ])
    ])
   
    stage('Prepare') { 
      echo "Prepare stage"
    }
  }
}
Error:
java.lang.UnsupportedOperationException: no known implementation of class hudson.triggers.Trigger is named RemoteBuildTrigger
	at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:549)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:473)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:585)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:458)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
Caused: java.lang.IllegalArgumentException: Could not instantiate {triggers=[{$class=RemoteBuildTrigger, remoteBuildToken=XXXXX}]} for org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty

It’s not possible to configure this I think. If you configure it manually you will get this xml

<flow-definition>
  ...
  <triggers/>
  <authToken>mySecretTriggerToken</authToken>
  ...
</flow-definition>

So you can see that this is not modelled as a trigger, hence you can’t configure it via triggers.

The approach to allow triggering of jobs this way is anyway not recommended.
Read the help that you get for this option for alternatives.