Home > OS >  Is it possible to trigger a multibranch pipeline jenkins build remotely?
Is it possible to trigger a multibranch pipeline jenkins build remotely?

Time:12-07

It seems only freestyle has that option. This appears to be outdated.

Jenkinsfiles do not appear to be able to read a remote trigger:

WorkflowScript: 8: Invalid trigger type "RemoteBuildTrigger". Valid trigger types: [upstream, cron, githubPush, pollSCM]

CodePudding user response:

Do not put anything in the triggers section. Have a Jenkinsfile like below.

pipeline {
    agent any
    stages {
        stage('Hello6') {
            steps {
                script {
                    script {
                        echo "Somethingggg"
                    }
                   
                }
            }
        }
   }
}

Then generate the token and then trigger the build. Following commands require curl and jq

# Change the following appropriately
JENKINS_URL="http://localhost:8080"
JENKINS_USER=admin
JENKINS_USER_PASS=admin

JENKINS_CRUMB=$(curl -u "$JENKINS_USER:$JENKINS_USER_PASS" -s --cookie-jar /tmp/cookies $JENKINS_URL'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')

#Get the Access token**
ACCESS_TOKEN=$(curl -u "$JENKINS_USER:$JENKINS_USER_PASS" -H $JENKINS_CRUMB -s \
                    --cookie /tmp/cookies $JENKINS_URL'/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken' \
                    --data 'newTokenName=GlobalToken' | jq -r '.data.tokenValue')

# You can get the correct URL by navigating to the branch build from the Jenkins console.
curl -X POST -u $JENKINS_USER:$ACCESS_TOKEN -H $JENKINS_CRUMB "$JENKINS_URL/job/$FOLDER_NAME/job/$MULTIBRANCH_JOB_NAME/job/$BRANCH_NAME/build"
  • Related