Bird
Raised Fist0
Jenkinsdevops~10 mins

Webhook triggers from GitHub/GitLab in Jenkins - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Jenkins pipeline that triggers on GitHub webhook events.

Jenkins
pipeline {
  agent any
  triggers {
    [1]()
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AgithubPush
Bcron
CpollSCM
Dtimer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pollSCM' instead of 'githubPush' triggers polling instead of webhook.
Using 'cron' or 'timer' triggers scheduled builds, not webhook events.
2fill in blank
medium

Complete the code to enable webhook trigger for GitLab in a Jenkins pipeline.

Jenkins
pipeline {
  agent any
  triggers {
    [1]()
  }
  stages {
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AgitlabPush
BgitPush
CgitlabWebhook
DgitPushTrigger
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gitPush' which is not a valid Jenkins trigger.
Using 'gitlabWebhook' which is not the correct trigger name.
3fill in blank
hard

Fix the error in the Jenkinsfile to correctly trigger on GitHub webhook push events.

Jenkins
pipeline {
  agent any
  triggers {
    [1]()
  }
  stages {
    stage('Deploy') {
      steps {
        echo 'Deploying...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AGitHubPush
Bgithubpush
Cgithub_push
DgithubPush
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or snake_case versions causes Jenkins to not recognize the trigger.
4fill in blank
hard

Fill the blank to create a Jenkins pipeline that triggers on GitLab webhook push events and runs a build stage.

Jenkins
pipeline {
  agent any
  triggers {
    [1]()
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building project...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
ApollSCM
BgithubPush
CgitlabPush
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing GitHub and GitLab trigger names causes the webhook not to work.
Using 'pollSCM' triggers polling, not webhook events.
5fill in blank
hard

Fill the blanks to define a Jenkins pipeline that triggers on GitHub webhook push events, checks out code, and runs tests.

Jenkins
pipeline {
  agent any
  triggers {
    [1]()
  }
  stages {
    stage('Checkout') {
      steps {
        {{BLANK_3}} 'https://github.com/example/repo.git'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AgithubPush
Cgit
Dcheckout
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'git' instead of 'checkout' for the code checkout step.
Using wrong trigger names for GitHub webhook events.

Practice

(1/5)
1. What is the main purpose of setting up a webhook trigger in Jenkins for GitHub or GitLab?
easy
A. To manually run Jenkins jobs from the Jenkins dashboard
B. To automatically start Jenkins jobs when code is pushed or pull requests are created
C. To send email notifications after a Jenkins job completes
D. To backup Jenkins configuration files to GitHub or GitLab

Solution

  1. Step 1: Understand webhook triggers

    Webhook triggers connect GitHub/GitLab events to Jenkins jobs, starting them automatically.
  2. Step 2: Identify the main use case

    The main use is to start Jenkins jobs automatically on code pushes or pull requests.
  3. Final Answer:

    To automatically start Jenkins jobs when code is pushed or pull requests are created -> Option B
  4. Quick Check:

    Webhook triggers = automatic job start [OK]
Hint: Webhook triggers start jobs automatically on code changes [OK]
Common Mistakes:
  • Confusing webhook triggers with manual job runs
  • Thinking webhooks send emails
  • Assuming webhooks backup Jenkins files
2. Which Jenkins pipeline syntax correctly sets up a GitHub webhook trigger to start a job on push events?
easy
A. triggers { cron('H/5 * * * *') }
B. triggers { gitlabPush() }
C. triggers { githubPush() }
D. triggers { genericWebhook() }

Solution

  1. Step 1: Recall GitHub webhook trigger syntax

    Jenkins uses genericWebhook() inside triggers block for generic webhook triggers, including GitHub.
  2. Step 2: Eliminate incorrect options

    gitlabPush() is not a valid Jenkins trigger; githubPush() is not a standard Jenkins trigger; cron() is for scheduled jobs.
  3. Final Answer:

    triggers { genericWebhook() } -> Option D
  4. Quick Check:

    Generic webhook trigger = genericWebhook() [OK]
Hint: Use genericWebhook() for GitHub webhook triggers in Jenkinsfile [OK]
Common Mistakes:
  • Using gitlabPush() which does not exist
  • Confusing genericWebhook() with GitHub trigger
  • Using cron for webhook triggers
3. Given this Jenkins pipeline snippet, what will happen when a push is made to the GitHub repository?
pipeline {
  agent any
  triggers {
    genericWebhook()
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building project'
      }
    }
  }
}
medium
A. The job will start automatically and print 'Building project'
B. The job will not start automatically; manual trigger needed
C. The job will fail due to syntax error in triggers
D. The job will start but skip the Build stage

Solution

  1. Step 1: Analyze the triggers block

    The genericWebhook() trigger means the job starts automatically on webhook events.
  2. Step 2: Check the pipeline stages

    The Build stage prints 'Building project' when the job runs.
  3. Final Answer:

    The job will start automatically and print 'Building project' -> Option A
  4. Quick Check:

    genericWebhook() triggers automatic build [OK]
Hint: genericWebhook() triggers auto build on webhook event [OK]
Common Mistakes:
  • Assuming manual trigger is needed
  • Thinking triggers block causes syntax error
  • Believing Build stage is skipped
4. A Jenkins job configured with GitLab webhook trigger does not start when code is pushed. Which is the most likely cause?
medium
A. The webhook URL in GitLab is incorrect or missing
B. The Jenkinsfile uses githubPush() trigger instead of GitLab webhook plugin
C. The Jenkins server is offline
D. The GitLab repository has no commits

Solution

  1. Step 1: Check webhook configuration in GitLab

    If the webhook URL is wrong or missing, GitLab cannot notify Jenkins to start the job.
  2. Step 2: Consider other causes

    Using githubPush() in Jenkinsfile won't trigger GitLab events; Jenkins offline stops all jobs; no commits means no push events.
  3. Final Answer:

    The webhook URL in GitLab is incorrect or missing -> Option A
  4. Quick Check:

    Webhook URL correct = trigger works [OK]
Hint: Verify webhook URL in GitLab settings first [OK]
Common Mistakes:
  • Ignoring webhook URL correctness
  • Confusing GitHub and GitLab triggers
  • Not checking Jenkins server status
5. You want to trigger a Jenkins job from GitLab using the Generic Webhook Trigger plugin. Which configuration step is essential to ensure the job starts only on push events?
hard
A. Use githubPush() trigger in Jenkinsfile and set GitLab webhook URL
B. Schedule the Jenkins job with cron to poll GitLab every 5 minutes
C. Configure the webhook in GitLab to send push event payloads and set the Generic Webhook Trigger to filter on push event type
D. Add a post-commit hook in GitLab that manually starts Jenkins jobs

Solution

  1. Step 1: Set GitLab webhook to send push event payloads

    GitLab must be configured to send push event data to Jenkins webhook URL.
  2. Step 2: Configure Generic Webhook Trigger plugin filters

    In Jenkins, set the plugin to trigger only when the payload indicates a push event.
  3. Final Answer:

    Configure the webhook in GitLab to send push event payloads and set the Generic Webhook Trigger to filter on push event type -> Option C
  4. Quick Check:

    Webhook + filter on push event = correct trigger [OK]
Hint: Filter webhook payload for push events in Jenkins plugin [OK]
Common Mistakes:
  • Using githubPush() for GitLab triggers
  • Relying on polling instead of webhooks
  • Manually triggering jobs instead of webhook automation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard