0
0
Jenkinsdevops~10 mins

API token management in Jenkins - Interactive Code Practice

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

Complete the code to create a new API token for a Jenkins user.

Jenkins
def create_api_token(user):
    token = user.[1]('new-token')
    return token
Drag options to blanks, or click blank then click option'
AgenerateToken
BcreateToken
CnewToken
DmakeToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'createToken' which is not a valid Jenkins user method.
Using 'newToken' or 'makeToken' which do not exist.
2fill in blank
medium

Complete the code to revoke an existing API token by its name.

Jenkins
def revoke_api_token(user, token_name):
    tokens = user.getApiTokens()
    tokens.[1](token_name)
    user.save()
Drag options to blanks, or click blank then click option'
AremoveToken
BdeleteToken
CrevokeToken
DclearToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'removeToken' which is not a Jenkins API method.
Using 'revokeToken' or 'clearToken' which do not exist.
3fill in blank
hard

Fix the error in the code to list all API tokens for a Jenkins user.

Jenkins
def list_tokens(user):
    tokens = user.[1]()
    for token in tokens:
        print(token.name)
Drag options to blanks, or click blank then click option'
AfetchTokens
BlistTokens
CretrieveTokens
DgetApiTokens
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listTokens' which is not a valid method.
Using 'fetchTokens' or 'retrieveTokens' which do not exist.
4fill in blank
hard

Fill both blanks to check if a token exists and then revoke it.

Jenkins
def revoke_if_exists(user, token_name):
    tokens = user.getApiTokens()
    if token_name [1] tokens:
        tokens.[2](token_name)
        user.save()
Drag options to blanks, or click blank then click option'
Ain
Bnot in
CdeleteToken
DremoveToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not in' instead of 'in' for the check.
Using 'removeToken' which is not a valid method.
5fill in blank
hard

Fill all three blanks to create a token, print its value, and save the user.

Jenkins
def create_and_show_token(user, token_name):
    token = user.[1](token_name)
    print(token.[2])
    user.[3]()
Drag options to blanks, or click blank then click option'
AgenerateToken
Bvalue
Csave
DtokenValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tokenValue' instead of 'value' property.
Forgetting to call 'save' on the user.