I'm trying to create a bamboo java spec for a simple plan creation. I don't see the plan created after enabling the scan for bamboo spec in linked repository. How to use the existing shared credentials to authenticate? Please let me know.
Hi Manasa,
I'm afraid you aren't facing the same issue from the question you mentioned. From what I understood, @Ryan Schaaf is using a Bitbucket Server repository to store his code and, in this case, there is no need to trigger the specs detection using a webhook (it's done through the application links).
As you probably already know, there is no way to create an application link between Bamboo and Bitbucket Cloud yet and that's the reason why the webhook is needed in this case.
On Bamboo 6.5.1 we added an option in Repository Configuration>>Specs Status to manually scan the repository for specs code without using a webhook:
While the improvement request mentioned by my colleague @Alexey Chystoprudov(BAM-19837) is not implemented, you can be creative and develop an external script calling the same endpoint used by the "Scan" button.
for example:
curl -u <USER>:<PASSWORD> -H 'content-type: application/json' -H 'accept:application/json' -X POST http://<bambooURL>/rest/api/latest/repository/<repositoryID>/scanNow
ps. You can find the <repositoryID> hovering the mouse over the linked repository name.
But first, of course, you'll need to upgrade Bamboo to 6.5.1 to have this endpoint available.
Please let me know what do you think about this workaround.
thanks.
Are you talking about the shared credentials for the repository authentication? If you are using a linked repository, your plan will use the credential set there, if you are using a plan repository, you'll need to define the shared credentials in your specs code:
i.e
<span>Plan</span> <span>plan</span> <span>=</span> <span>new</span> <span>Plan</span><span>(</span><span>project</span><span>,</span> <span>planName</span><span>,</span> <span>planKey</span><span>)</span> <span>.</span><span>planRepositories</span><span>(</span><span>new</span> <span>GitRepository</span><span>()</span> <span>.</span><span>name</span><span>(</span><span>"my-repository"</span><span>)</span> <span>.</span><span>url</span><span>(</span><span>"ssh://git@bitbucket.org:my-company/my-repository.git"</span><span>)</span> <span>.</span><span>branch</span><span>(</span><span>"master"</span><span>)</span> <span>.</span><span>authentication</span><span>(</span><span>new</span> <span>SharedCredentialsIdentifier</span><span>(</span><span>"identifier"</span><span>)));</span>
(from Bamboo Specs Reference)
But, if you are talking about the permissions used by Bamboo to run your specs code, it does not use any specific user, Bamboo uses a system account with the permissions you set specifically for the repository where you're storing the specs code.
thanks
Hi Gabriel, Thank you for the response. So when i try to run the java spec from my local computer i use my credentials in .credentails file. When i try to add the java spec to a git repository and enable bamboo spec scanner, i don't see the plan created. We have shared credentials to authenticate the repo on Bamboo. Does your code help me with my issue?
I don't think so, your specs code is probably not running because your repository does not have access rights to the project where you're trying to create/edit the plan. When using RSS (repository stored specs) you need to explicitly give permission for the repository to the project (Project settings > Bamboo Specs repositories).
I have added that settings but i still don't see my plan has been created. Do i need to have .credentials file available within bamboo-specs repository?
No, the .credentials file is not used in repository stored specs, this is only used while publishing your plans using maven or the IDE.
Hi Gabriel,
As per my observation, when i create a plan using bamboo.yaml in my project all i need to trigger is the webhook url provided in the Bamboo Specs tab. The plan is getting triggered for every new commit as well without any webhooks after the plan has been created.
https://company.com/rest/api/latest/repository/scan?repositoryId=
bamboo-test.git
|_ bamboo-specs
|_ bamboo.yaml
When i create a bamboo plan using a java spec, i need to trigger using the webhook to create the plan/update any changes to plan using the spec. It doesn't trigger any code updates later, manually running the curl for new code commits works.
- bamboo-specs
|_ src/main/java/CreatePlan.java
curl -X POST -H "Content-Type: application/json" https://company.com/rest/triggers/1.0/remote/changeDetection?planKey=TEST-BT&skipBranches=false
Above curl works for the plan created through java spec for new commits. It doesn't trigger the plan for new code changes just like the one created by yaml.
Please let me know your thoughts!
Thanks!
I'm not sure if we are talking about the same thing here, let's see.
When you call the "https://company.com/rest/api/latest/repository/scan?repositoryId=" API endpoint (using cURL o via SCM webhook), Bamboo will trigger the Repository Stored Specs feature that will be responsible for "sweeping around" your repository looking for specs code (it doesn't matter if it is in Java or YAML). It will neglect all code that can possibly be in your repository other than the files inside the repositoryRoot/bamboo-specs/ folder. If Bamboo finds a possible specs code, it will pull and process this code using an environment specifically developed for this purpose.
On the other hand, the "https://company.com/rest/triggers/1.0/remote/changeDetection?planKey=TEST-BT&skipBranches=false" API is designed to trigger the change detection functionality and check if there were changes in the default repository for the plan specified in the API URL (in this case: TEST-BT) since the previous build. If there were change, the entire repository will be checked out and all the stages/jobs specified in your plan configuration will be executed. This procedure has no relations to Repository Stored Specs and Bamboo will not process you specs project unless this plan was meant to process you Java Specs as a regular Maven/Java project.
From my understanding, this is what you're experiencing right now:
If you have the specs code (Java or YAML) in the repository and curl the "https://company.com/rest/api/latest/repository/scan?repositoryId=" endpoint, Bamboo Specs will run and create/update your plans but when you call the "https://company.com/rest/triggers/1.0/remote/changeDetection?planKey=TEST-BT&skipBranches=false" API endpoint, the builds get triggered but your plans are being updated by Bamboo Specs.
Is this correct?
So i'm finding a difference in code detection for a JAVA Spec and YAML.
"https://company.com/rest/api/latest/repository/scan?repositoryId=" endpoint is helping in triggering the spec updates for java and YAML but after the plan is created for any new code commits,
Plan created by YAML
- Triggers a build for all new commits without any webhooks.
Plan created by Java Spec
- Doesn't trigger any build.
Hope its clear, let me know. Thanks!
It looks like you're new here. Sign in or register to get started.