How to associate a project with a quality profile in Sonarqube - rest

I am using sonar webapi to associate a project with a quality profile but not able to do it. On every run of sonnar-scanner it is associating default quality profile. Below is the code snippet.
Updated the code snippet
curl -k -X POST --insecure -H “X-Auth-Token:XXX” -d "language=py" -d "qualityProfile=test_profile" -d “project=test_1.0” https://sonartest.xxx.com/api/qualityprofiles/add_project
I am not sure what I am doing wrong. I have administrative access and followed the webapi of Version 6.7.3 (build 38370)

Finally got some help from Soanrqube community. I need to remove X-Auth-Token from code. It should be something like this
curl -u ur_token: -X POST -d language=py -d qualityProfile=test_profile -d projectKey=${params.ProjectName} https://sonar-url.com/api/qualityprofiles/add_project

Related

Can't download using Nexus 3 REST API and CURL

I'm trying to download the latest snapshot dependency of a zip on Nexus 3 (version 3.22.1-02) from a command line using curl:
curl -u username:password -X GET "https://mynexusserver/service/rest/v1/search/assets/download?sort=version&repository=snapshotsrepo&maven.groupId=mygroup&maven.artefactId=myartefact&maven.extension=zip" -H "accept: application/json" -o myartefact.zip
This request is similar to this example: http://help.sonatype.com/repomanager3/rest-and-integration-api/search-api#SearchAPI-DownloadingtheLatestVersionofanAsset but no result is returned, myartefact.zip is empty.
However with the same URL, my artefact is downloaded from a web browser or with gradle.
With curl the following command line is working fine, returning the list of all snapshot versions of my artefact:
curl -u username:password -X GET "https://mynexusserver/service/rest/v1/search/assets?sort=version&repository=snapshotsrepo&maven.groupId=mygroup&maven.artefactId=myartefact&maven.extension=zip" -H "accept: application/json" -o myartefact.zip
Downloading the artefact directly is working fine as well with a command line like:
curl -u username:password "https://mynexusserver/repository/snapshotsrepo/mygroup/batchfactory/myversion-SNAPSHOT/myartefact-myversion-mytimestamp.zip" -H "accept: application/json" -o myartefact.zip
Verbose logs (-v option) show the artefact is found (I get HTTP/1.1 302 Found message) but nothing is downloaded.
Using wget doesn't work any better, I can't even query the list of snapshot version of the artefact.
Am I missing something?
Thanks #Zeitounator, after adding "-L" the command line works fine. Considering code 302 this feels obvious now...
Nexus documentation should also probably be updated to add the "-L" option.

Create Bitbucket Pull Request Comment via REST

I want to create a bitbucket comment after finishing my bamboo build. Unfortunately my rest call didnt work. ALso Im getting no response.
Am I missing something?
curl -u "USER:PASSWORD" -X POST -d '{"body": "Your Message to Comment"}' "http://URL/2.0/repositories/OWNER/REPO/pullrequests/ID/comments"
Execute the following command:
curl -u "USER:PASSWORD" --request POST --data '{"text": "YOUR-COMMENT"}' "BITBUCKET-SERVER/rest/api/1.0/projects/PROJECT/repos/REPO/pullrequests/ID/comments"

cURL command failed to delete pull-request from bit bucket with 400 error

I am trying to delete a pull-request from bitbucket. I am using the following command,
curl -v -u {username}:{password} -X DELETE -H "Content-Type:application/json" https://{bitbucket.com}/rest/api/1.0/projects/{project_name}/repos/{repo_name}/pull-requests/{pull-request_id}
but the command fails with an error code 400. Please find the error:
{"errors":[{"context":null,"message":"No content to map to Object due to end of input","exceptionName":"java.io.EOFException"}]}.
I think I am missing something in the rest url. Please help me to resolve the issue. Thanks in advance
You need to pass the "version" of the pull-request (remember that the pull-request version starts in 0). Add the "-d #-" option to send the version in a here-document.
curl -v -u {username}:{password} -d #- -X DELETE -H "Content-Type:application/json" https://{bitbucket.com}/rest/api/1.0/projects/{project_name}/repos/{repo_name}/pull-requests/{pull-request_id} <<EOF
{
"version": {version}
}
EOF

CQ5.5 Updating an existing package through CURL

I am using a series of CURL request to create my package.
What I am doing currently: I created a new package, added filters to it and then built the package.
Create package:
curl -f -N -u ${USER}:${PASS} -d "packageName=${PACKAGE}&groupName=${GROUP}" "${CMS_HOST}/crx/packmgr/service/exec.json?cmd=create"
Apply Filters:
curl -f -N -u ${USER}:${PASS} -F "path=/etc/packages/${GROUP}/${PACKAGE}.zip" -F "packageName=${PACKAGE}" -F "groupName=${GROUP}" -F "version=" -F "description=" -F "thumbnail=" -F "filter=${FILTER}" -F "_charset_=UTF-8" "${CMS_HOST}/crx/packmgr/update.jsp"
Build Package:
curl -f -N -u ${USER}:${PASS} -d "cmd=build" "${CMS_HOST}/crx/packmgr/service/script.html/etc/packages/${GROUP}/$PACKAGE.zip"
What I want to do: Add more filters to this package and build it again.
I am wondering if there is a way to update an existing package. I have been searching around to see how we can do this but have failed. Can someone please help me?
Thanks.
Update: Added the CURL commands I am using.
Here you go with an example where i have a package with two filters already
Going to add another filter
CURL for Create a Filter Node
curl --data jcr:primaryType=nt:unstructured --user admin:admin http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2
Add the Filter properties
curl -u admin:admin -Froot="/content/geometrixx-outdoors/en/toolbar" http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2.rw.html
IF required add additional properties (i.e. "mode" & "rules") for the Default package behaviour
curl -u admin:admin -Fmode="replace" http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2.rw.html
curl -u admin:admin -Frules#TypeHint="String[]" -Frules=" " -Frules=" "http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2.rw.html
Finally build your package to affect additional filter to add to your existing package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/testcurl.zip?cmd=build
All the packages are stored under /etc/packages/my_packages path which can be modified by standard curl commands for node management. All packages have filters as sub-nodes.
All package manager commands are available via /crx/packmgr/service.jsp?cmd=help
For example, in order to build a package use /crx/packmgr/service.jsp?cmd=build

Create jobs and execute them in jenkins using REST

I am trying to create a WCF REST client that will communicate to Jenkins and create a job from an XML file and then build the job. My understanding is that you can do that with Jenkins.
Can some one please provide some commands that you can type on a browser's address bar to create and build jobs? ie: http:localhost/jenkins/createItem?name=TESTJOB something along those lines.
Usually, when parsing through the documentation, it can take one or two days. It is helpful to be able to access code or curl commands to get you up and running in one hour. That is my objective with a lot of third party software.
See the post at http://scottizu.wordpress.com/2014/04/30/getting-started-with-the-jenkins-api/ which lists several of the curl commands. You will have to replace my.jenkins.com (ie JENKINS_HOST) with the your own url.
To create a job, for instance, try:
curl -X POST -H "Content-Type:application/xml" -d "<project><builders/><publishers/><buildWrappers/></project>" "http://JENKINS_HOST/createItem?name=AA_TEST_JOB2"
This uses a generic config. You can also download a config from a manually created job and then use that as a template.
curl "http://JENKINS_HOST/job/MY_JOB_NAME/config.xml" > config.xml
curl -X POST -H "Content-Type:application/xml" -d #config.xml "http://JENKINS_HOST/createItem?name=AA_TEST_JOB3"
To execute the job (and set string parameters), use:
curl "http://JENKINS_HOST/job/MY_JOB_NAME/build"
curl "http://JENKINS_HOST/job/MY_JOB_NAME/buildWithParameters?PARAMETER0=VALUE0&PARAMETER1=VALUE1"
See the Jenkins API Wiki page (including the comments at the end). You can fill in the gaps using the documentation provided by Jenkins itself; for example, http://JENKINS_HOST/api will give you the URL for creating a job and http://JENKINS_HOST/job/JOBNAME/api will give you the URL to trigger a build.
I highly recommend avoiding the custom creation of job configuration XML files and looking at something like the Job DSL plugin instead. This gives you a nice Groovy-based DSL to create jobs programmatically - much more concise and less error-prone.
Thanks to a GIST - https://gist.github.com/stuart-warren/7786892
Check if job exists
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken
With folder plugin
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary #config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
Without folder plugin
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary #config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
Create folder
curl -XPOST 'http://jenkins/createItem?name=FolderName&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22FolderName%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK' --user user.name:YourAPIToken -H "Content-Type:application/x-www-form-urlencoded"
If you want to create a job into a view given the view exists.
curl -X POST -H "Content-Type:application/xml" -d #build.xml "http://jenkins_host/view/viewName/createItem?name=itemName"
the build.xml filetemplate could be found in the root directory of a job's workspace
if you want to create a view:
curl -X POST -H "Content-Type:application/xml" -d #view.xml "http://jenkins_host/createView?name=viewName"
the content of the file view.xml could be:
<?xml version="1.0" encoding="UTF-8"?>
<hudson.model.ListView>
<name>viewName</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
<jobNames>
<comparator class="hudson.util.CaseInsensitiveComparator"/>
</jobNames>
<jobFilters/>
<columns>
<hudson.views.StatusColumn/>
<hudson.views.WeatherColumn/>
<hudson.views.JobColumn/>
<hudson.views.LastSuccessColumn/>
<hudson.views.LastFailureColumn/>
<hudson.views.LastDurationColumn/>
<hudson.views.BuildButtonColumn/>
</columns>
</hudson.model.ListView>
and to check if a view exists:
curl -X POST -H "Content-Type:application/xml" "http://jenkins_host/checkViewName?value=viewName"
to check if a job exists:
curl -X POST -H "Content-Type:application/xml" "http://jenkins_host/checkJobName?value=jobName"
To create a job:
curl -X POST -H "Content-Type:application/xml" -d "<project><builders/><publishers/><buildWrappers/></project>" -u username: API_Token http://JENKINS_HOST/createItem?name=AA_TEST_JOB2
To build a job:
curl -X POST -u username:API_TOKEN http://JENKINS_HOST/job/MY_JOB_NAME/build
In case you need to make the same HTTP calls using the Python requests library, instead of CURL...
Download a job config:
import requests
auth = ("username", "api_token")
url = "http://" + JENKINS_HOST + "/job/" + JOB_NAME + "/config.xml"
response = requests.get(url, auth=auth)
open('config.xml', 'wt').write(response.text)
Create a new job using same config:
url = "http://" + JENKINS_HOST + "/createItem?name=" + NEW_JOB_NAME
headers = {'content-type': 'text/xml'}
data = response.text
response = requests.post(url, auth=auth, headers=headers, data=data)
Omit auth parameter when not needed.