Does anyone know how to use httpRequest in Jenkinsfile pipeline with basic auth? I checked in the https://github.com/jenkinsci/http-request-plugin, they support Supports Basic Authentication (see global configuration). But when i implemented in my groovy script, i found the following errors. Can anyone show how to pass the user name and password to the httprequest.
def masterDataReplicatorTriggerDeployment() {
milestone 40
VaultUtil vaultUtil = PipelineUtil.getInstance(this).getProdVaultUtil()
def ROUTER_USER
def ROUTER_PASS
def baseurl="http://master-data-replicator.cfapps.us10.hana.ondemand.com"
def sourcetenant="revcdevkp"
def targettenant="revcdevpo"
def copyBCdata="/replicator/v1/businessConfig/"
def response
ROUTER_USER=vaultUtil.readCredential
("secret/landscapes/infrastructure/router").get("router.security.username")
ROUTER_PASS=vaultUtil.readCredential
("secret/landscapes/infrastructure/router").get("router.security.password")
response = httpRequest url:
baseurl+copyBCdata+sourcetenant+"/"+targettenant,
httpMode: 'POST',
authentication: [Username: ROUTER_USER, Password: ROUTER_PASS]
}
org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class java.lang.String at org.kohsuke.stapler.ClassDescriptor.loadConstructorParamNames(ClassDescriptor.java:247) at org.jenkinsci.plugins.structs.describable.DescribableModel.(DescribableModel.java:122) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:380) at
def creds = "ROUTER_USER:ROUTER_PASS"
String auth = creds.bytes.encodeBase64().toString()
httpRequest consoleLogResponseBody: true,
url: baseurl+copyBCdata+sourcetenant+"/"+targettenant,
customHeaders:[[name:'Authorization', value:"Basic ${auth}"]]
The new problem: 401 authrization problem. But i did use the right credential and can visit them.
I know my format of authentication is not correct, do you know which supposed to be the correct way? Thanks.
Best Regards,