// Pipeline de construction des images Docker des services Zéphir def call() { pipeline { agent { label 'common' } parameters { string( name: 'targetUrl', description: 'URL cible pour l\'audit' ) string( name: 'basicAuthUsername', description: "Nom d'utilisateur pour l'authentication 'Basic Auth' (si besoin)" ) password( name: 'basicAuthPassword', description: "Mot de passe pour l'authentication 'Basic Auth' (si besoin)" ) string( name: 'basicAuthDomain', description: "Nom de domaine pour l'authentication 'Basic Auth' (si besoin)" ) string( name: 'authFormUrl', description: "URL du formulaire d'authentication (si besoin)" ) string( name: 'authFormUsername', description: "Nom d'utilisateur du formulaire d'authentication (si besoin)" ) password( name: 'authFormPassword', description: "Mot de passe du formulaire d'authentication (si besoin)" ) string( name: 'authFormCheckUrl', description: "URL de vérification de la réussite de l'authentication (si besoin)" ) string( name: 'authFormCheckString', description: "Chaine de caractères à rechercher pour vérifier la réussite de l'authentication (si besoin)" ) string( name: 'authFormDataFormat', description: "Patron de formatage des données POST du formulaire d'authentification (si besoin). Exemple: username=%U&password=%P" ) } stages { stage("Check parameters") { steps { script { if (!params.url?.trim()) { error("L'URL cible n'est pas définie !") } } } } stage("Test URL") { steps { script { def w3afImage = buildDockerImage() def dockerArgs = """ -e W3AF_TARGET='${params.targetUrl}' -e W3AF_BASIC_AUTH_USERNAME='${params.basicAuthUsername}' -e W3AF_BASIC_AUTH_PASSWORD='${params.basicAuthPassword}' -e W3AF_BASIC_AUTH_DOMAIN='${params.basicAuthDomain}' -e W3AF_AUTH_FORM_URL='${params.authFormUrl}' -e W3AF_AUTH_FORM_USERNAME='${params.authFormUsername}' -e W3AF_AUTH_FORM_PASSWORD='${params.authFormPassword}' -e W3AF_AUTH_FORM_CHECK_URL='${params.authFormCheckUrl}' -e W3AF_AUTH_FORM_CHECK_STRING='${params.authFormCheckString}' -e W3AF_AUTH_FORM_DATA_FORMAT='${params.authFormDataFormat}' """ w3afImage.inside(dockerArgs) { sh 'mkdir reports' sh 'envtpl -o audit.w3af audit.w3af.tmpl' sh './w3af_console -y -n -s audit.w3af' } } } } } post { always { publishHTML target: [ allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true, reportDir: 'reports', reportFiles: 'report.html', reportName: "Rapport d'audit" ] } failure { // wrap([$class: 'BuildUser']) { // rocketSend ( // avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png', // message: """ // Le test de sécurité pour `${params.targetUrl}` a échoué: // [Voir le job](${env.RUN_DISPLAY_URL}) // @${env.BUILD_USER_ID ? env.BUILD_USER_ID : 'here'} // """.stripIndent(), // rawMessage: true // ) // } } } } } def buildDockerImage() { dir ('.w3af') { def dockerfile = libraryResource 'com/cadoles/w3af/Dockerfile' writeFile file:'Dockerfile', text:dockerfile def audit = libraryResource 'com/cadoles/w3af/audit.w3af' writeFile file:'audit.w3af', text:audit def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-') def imageTag = "${safeJobName}-${env.BUILD_ID}" return docker.build("w3af:${imageTag}", ".") } }