I have a script to trigger a job on Jenkins remotely using a token. Here is my script:
JENKINS_URL=\'http://jenkins.myserver.com/jenkins\'
JOB_NAME=\'job/uti
When you trigger a job, the job is placed into the queue. The actual build is created only when it starts running and at that point the build gets a build number. If all your executors are busy, it can sometimes take a long time before the build is created and starts running.
The only way to get the build number when triggering a job, is to use the "build" command of the Jenkins CLI. If you use the -w option, the command will not return until the build starts and then it will print "Started build #N"
You do not actually need the java cli.jar, just an ssh client is enough. See https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+SSH
Other than that there is no known solution. You might be able to search through the builds and find a one that was triggered around the time your triggered the job, but that's a lot of work.