Masking Basic Auth header when using CURL to trigger remote jenkins job - docker

I want to trigger remote Jenkins job from my container(k8s).
Currently, I'm using:
curl -k -X POST -u $USER:$JENKINS_TOKEN "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345"
But this information($USER,$JENKINS_TOKEN) is displayed in ArgoUI, is there any secure/other way to save credentials for remote trigger?

You can try one of the following.
Save the password in a file called password-file and read from that
curl -k -X POST -u $USER:$(cat .password-file)"${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345"
Accept credentials from the STDIN.
curl -k -X POST "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345" -K- <<< "--user $USER:$JENKINS_TOKEN"
You can also try using --netrc-file option with curl where you can store the username and password in a file itself.
file
machine JENKINS_HOST login USERNAME password PASSWORD
Curl Command
curl -k -X POST --netrc-file my-password-file "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters?token=12345"

Related

Can any one please provide Curl Command to get Artifact from Nexus in Jenkins file

Please provide Curl command to download the artifact from nexus with username and password.
The Assets API mentions how to get the download URL for some asset, and it uses username and password with curl:
curl -u admin:admin123 -X GET 'http://localhost:8081/service/rest/v1/assets?repository=maven-central'
Once you have that, run curl again with the download URL you obtained:
curl -u admin:admin123 -X GET 'http://localhost:8081/repository/maven-central/asm/asm/3.1/asm-3.1-sources.jar'

Mask credentials in Jenkins script shell

I added credentials in Credentials Binding Plugin in Jenkins.
Then I send this credentials as text to company's chat in Execute shell section using curl with data parameter:
curl --silent $url -d "{ \"text\": \"$credentials\" }" -H "X-Auth-Token: $auth_token" -H "X-User-Id: $user_id" -H "Content-type:application/json"
And I receive unmasked credentials in chat. How can I mask credentials or modify Binding plugin which will mask secret text same as echo output

How to pass credential id in curl command

I am using below curl command to upload file in nexus.
curl -v -L -user "id":"password" --upload-file /jenkins/workspace/Raghu/SonarQube/target/spring-petclinic-2.0.0.BUILD-SNAPSHOT.jar https://uat.alm.com/nexus/content/repositories/NexusTest1_Snapshot/2.0/
I want to use credentials Id : "ff154118-e8d1-4c40-a63b-5ce5821c347c" instead of id and password.
Please help me how can i use it.

Gerrit Authentication required

I'm working on some automation for Gerrit. I have used following API to check access
curl -X POST --digest -k --user username:password https://gitAccess/access/
But returns authentication required. Can you please help me
3 things to note as I was also getting an "unauthorized" when trying to access Gerrit APIs
Make sure you have your HTTP password. This is different from the
password you use to login to Gerrit. To get it, go to gerrit ->
click on your username -> Settings -> HTTP Password -> Click on
generate password. Use this password when making HTTP requests
Prefix /a to the endpoint URL as mentioned here. For example /changes becomes /a/changes when using authentication
Use the --digest option if you are using curl as mentioned here
Example
curl --digest -u <USERNAME> -i -H "Accept: application/json" "https://<GERRIT SERVER>/a/changes"
# curl will prompt you for the password. You can also do it as below
curl --digest --user <USERNAME:PASSWORD> -i -H "Accept: application/json" "https://<GERRIT SERVER>/a/changes"

Trigger jenkins job with parameters from shell

I am trying to trigger a trigger jenkins job from shell but as of now no sucess.I tried both these methods
curl -u ceadmin:ceadmin -X POST http://abc-lnx:8080/job/ci_demo/build --data token=ci_build -data-urlencode json='{"parameter": [{"name":"Branch", "value":"master"}, {"name":"verbosity", "value":"high"}]}'
curl -X POST http://abc-lnx:8080/job/ci_demo/buildWithParameters?token=ci_build&Branch=master
I have defined ce_admin as token in my job. also ce_admin is a admin user in Jenkins.Anonymous user do not have any permission other then read on jobs and views.
What am i missing?
This works for me:
#parameters:
username=user
password=password
jenkins_url=example.com/build
some_token=hi
job_name=dostuff
curl -u $username:$password -X POST https://$jenkins_url/job/$job_name/build\?token\=$some_token
So this should work for your example (I escaped "?", and "&"):
curl -u ceadmin:ceadmin -X POST http://abc-lnx:8080/job/ci_demo/buildWithParameters\?token=ci_build\&Branch=master

Resources