jenkins the definitive guide

(Jeff_L) #1

Figure 7.15. Using custom scripts to handle authentication


Before invoking the authentication script, Jenkins sets two environment variables: U, containing the
username, and P, containing the password. This script uses these environment variables to authenticate
using the specified username and password, returning 0 if the authentication is successful, and some
other value otherwise. If authentication fails, the output from the process will be reported in the error
message displayed to the user. Here is a simple Groovy authentication script:


def env = System.getenv()
def username = env['U']
def password = env['P']

println "Authenticating user $username"

if (authenticate(username, password)) {
System.exit 0
} else {
System.exit 1
}

def authenticate(def username, def password) {
def userIsAuthenticated = true
// Authentication logic goes here
return userIsAuthenticated
}

This script is enough if all you have to deal with is basic authentication without groups. If you want to
use groups from your custom authentication source in your Matrix-based or Project-based authorizations

Free download pdf