Use rest api with jquery to run a deploy?

Hello,

 

I am looking for enough information on how to create a web page to run a deploy that is scheduled.  I was able to cobble together something that shows the projectId, environmentId, and versionId list (release numbers), and even a calendar to let users pick a date and time, but I am having trouble actually submitting a form that will do something with the information.  I tried $.ajax for example:

 

First off, authentication is a mystery.
 
However, it would be best if it used an auth token.  All I see out there is how to create tokens for Jira or Confluence, but nothing for Bamboo.  The steps do not work.        
 
I think as long as I am logged in to bamboo, no other authentication, and I am guessing if a user were to us this, they would need to have deploy permission to the project.  Yes, yes, why not just use Bamboo (sigh).  This has to do with wanting to use some product called servicenow, so that product will need to run "Something" to do the work for the user.
 
I still do not know what rest api call is used to include a scheduled time.  I tried to simply run a deploy. Note I tried jsonp to deal with cors, but if you have the magic to get this working, I would love to hear it (application link?  what do you fill in if you have to set that up and where/how do you get the info to setup an application link?:  
 
     var url = "https://mydomain.com/bamboo/rest/api/latest/queue/deployment/";
             url += "?environmentId=" + $('#environment').val();
             url += "&versionId=" + $('#release').val();

                console.log(url);
                alert(url);
                $.ajax({
                        type: 'POST',
                        url: url,
                        data: "",
                        dataType: 'jsonp',
                        async: 'false',
                        success: function() {
                                alert("POSTED");
                        },
                        error: function() { alert("failed!"); }
                });
        }
Whatever I do it will either run and show no error (no alert box pops up), but it will not run deploy, or it will throw:
 
XMLHttpRequest cannot load https://esapps.sas.com/bamboo/rest/api/latest/queue/deployment/?environmentId=95158277&versionId=94470491?os_authType=basic. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://favorites.unx.sas.com' is therefore not allowed access. The response had HTTP status code 401.


I see there is a whitelist option in Bamboo, but it does not let me do anything with it and it does not seem to be REST API related (maybe just for java or plugins).
 
With jsonp sometimes it says:
 
Refused to execute script from 'https://esapps.sas.com/bamboo/rest/api/latest/queue/deployment/?environment…e=basic&callback=jQuery110208378970937783805_1485533032763&_=1485533032764' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
 
I am praying somebody can give enough information to do the following:
1. setup token authentication
2. use the token with jquery $.ajax call to run the deployment
3. show me what i need to tack onto the url to also include a schedule for the trigger event.

1 answer

This widget could not be displayed.

Personally, I would just have the jquery send to a webservice (hosted somewhere, maybe even on the bamboo box itself) and have the webservice perform the magic, and return the information back to the jquery call.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

64 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you