Complete the code to create a new API token for a Jenkins user.
def create_api_token(user): token = user.[1]('new-token') return token
The correct method to generate a new API token in Jenkins user object is generateToken.
Complete the code to revoke an existing API token by its name.
def revoke_api_token(user, token_name): tokens = user.getApiTokens() tokens.[1](token_name) user.save()
The method to delete an API token by name in Jenkins is deleteToken.
Fix the error in the code to list all API tokens for a Jenkins user.
def list_tokens(user): tokens = user.[1]() for token in tokens: print(token.name)
The correct method to get all API tokens from a Jenkins user is getApiTokens.
Fill both blanks to check if a token exists and then revoke it.
def revoke_if_exists(user, token_name): tokens = user.getApiTokens() if token_name [1] tokens: tokens.[2](token_name) user.save()
Use in to check if the token exists, then deleteToken to revoke it.
Fill all three blanks to create a token, print its value, and save the user.
def create_and_show_token(user, token_name): token = user.[1](token_name) print(token.[2]) user.[3]()
Use generateToken to create, value to get the token string, and save to persist changes.
