how to use httpRequest in Jenkinsfile pipeline with basic auth how to use httpRequest in Jenkinsfile pipeline with basic auth jenkins jenkins

how to use httpRequest in Jenkinsfile pipeline with basic auth


Use the credential plugin Credential plugin for storing your credentials. Then use the ID in the httpRequest.

Example :New credentialScope : GlobalUsername : my_technical_userPassword : *******ID : my_user_idhttpRequesthttpRequest httpMode: 'POST',url: "${baseurl}${copyBCdata}${sourcetenant}/${targettenant}",authentication: 'my_user_id'

Or you can inject your username and password on the header directly.

def creds = "your_username:your_password"String auth = creds.bytes.encodeBase64().toString()httpRequest  consoleLogResponseBody: true,               url: "your_url",                                    customHeaders:[[name:'Authorization', value:"Basic ${auth}"]]