HI, I have created a project through web api call in sonarqube and i want to “configure analysis” for my project with “other ci” option and use the existing token.
for ex: https://sonarqube_url/api/api/projects/create" “name=test-project” -d “key=test-project” -d “project=test-project” -d “mainBranch=develop”
jus tlike above to create project, any api to add token for the above created project?
I don’t know which api needs to be added here.
This needs to be done over web api call, if any help is provided it would be great.
the web api call for creating a token for a specific project is api/user_tokens/generate
with the parameters projektKey=yourprojectKey and type=PROJECT_ANALYSIS_TOKEN
see https://<yoursonarhost>/web_api/api/user_tokens/generate
Thanks for the response Rebse , i need bit more clarification and can you provide by giving an example.
In my case now,
I have created the “GLOBAL_ANALYSIS_TOKEN” using below command:
curl -u $USERNAME:$PASSWORD “http://$SONAR_IP:9000/api/user_tokens/generate” -d “name=sonarqube_token” -d “type=GLOBAL_ANALYSIS_TOKEN” -d “expirationDate=$(date --date=”+90 days" +%Y-%m-%d)"
and I have created project using:
curl -u $USERNAME:$PASSWORD -X POST “http://$SONAR_IP:9000/api/projects/create” -d “name=demoproject” -d “key=demoproject” -d “project=demoproject” -d “mainBranch=develop”
Now, How can I use my existing Global token which is created above in “demoproject”. Can you please provide the Web API with example.
It’s simply using <token>: instead of username:password for your web api calls, means just the token with separator and a blank password.
WRT to the CI configuration
there’s normally a technical user with full admin permissions.
Its token of type usertoken is then configured for the use in your pipelines / build jobs.
We use Jenkins and there is a Sonarqube Jenkins extension available that takes the usertoken.
You didn’t mention your CI system, but there are integrations for other CI systems too.
After all you may set an environment variable for the admin usertoken and use that.
can i pass this “sonar.login” while creating project itself through web API, please provide as example to pass this while creating project using my existing “GLOBAL_ANAYSIS_TOKEN”.