Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Jenkins library in Python.
Selenium Python
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using selenium instead of jenkins for Jenkins integration.
Importing requests which is for HTTP calls but not Jenkins specific.
✗ Incorrect
The jenkins library is used to interact with Jenkins servers in Python.
2fill in blank
mediumComplete the code to create a Jenkins server object with URL 'http://localhost:8080'.
Selenium Python
server = jenkins.Jenkins([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using IP address instead of 'localhost'.
Forgetting quotes around the URL string.
✗ Incorrect
The Jenkins server URL is usually 'http://localhost:8080' when running locally.
3fill in blank
hardFix the error in the code to trigger a Jenkins build for job 'TestJob'.
Selenium Python
server.[1]('TestJob')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'start_build' or 'run_job'.
Confusing method names that do not exist in the Jenkins API.
✗ Incorrect
The correct method to start a Jenkins job build is build_job.
4fill in blank
hardFill both blanks to check if the last build of 'DeployJob' was successful.
Selenium Python
last_build_number = server.get_job_info('DeployJob')['[1]']['number'] status = server.get_build_info('DeployJob', last_build_number)['[2]']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys like 'buildStatus' or 'last_build'.
Confusing the keys for job info and build info.
✗ Incorrect
The key to get the last build number is lastBuild. The build result status is under result.
5fill in blank
hardFill all three blanks to trigger a build with parameters for job 'TestJob'.
Selenium Python
params = {'branch': 'main', 'env': 'staging'}
server.[1]('TestJob', [2]=[3]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build_with_parameters' instead of 'build_job'.
Mixing up argument names and variable names.
✗ Incorrect
To trigger a parameterized build, use build_job method with parameters=params.