Bitbucket and ServiceNow Integration - How it Works
[Music] hey everyone it's Justin thank you for watching and welcome to my house that's Justin's house in this video I'm going to show you behind the scenes on how my bitbucket and agile teams and servicenow integration actually works and it was really really simple so if you remember if you've seen the video I'll link to it up above I'll provide a link where I show the actual integration what's going on in this video I'm basically going to show what I did to make a story which you can see up here on the screen behind me receive a commit from bitbucket and Associate it with the story that you're seeing down here so I have a list of commits that someone made in bitbucket being associated with a story in service now so really it all starts over in bitbucket when I went into my repo and configured a web hook over here on the right left hand side I made sure that a web Hook was going to call service now whenever somebody made a commit you can see here I'll just go ahead and edit this what I did is I said hey go to this URL and I want you to do this anytime someone makes a commit in this particular repository and in this case that's a push in bitbucket terms and it'll go ahead and call that URL it's going to be blurred out I'm sorry it has my my job plot servicenow instance and it'll do that particular function that we want so how is that happening basically or not basically what I did is I set up a flow and you can see here there's a trigger and four actions for this entire integration so the trigger is the URL that that web hook in bitbucket is calling so that's this right here when you use this rest API Dash asynchronous trigger it's essentially creating a rest endpoint in your servicenow instance so that someone can call it now you can require that that asks for Authentication uh when they uh move my cursor back here see this authentication button here so I could check that and actually it required re-authentication and then assign a role for somebody to access for demo purposes I didn't do any authentication the second thing that I did is that I built out the response body or the request body for what the fields that I wanted so for this particular one I wanted to type the hash the date the author the message and the links associated with it so I could put those in the commit record in service now and then associate with the story that's the first part that triggers all this process all here in this rest API asynchronous then I'm going to create the record now there's a table that I created for bitbot commit records and then I'm just going to create a record in there with the info I found here's the disappointing part is that I wasn't able to drag and drop the data pills over into this action so that's where the low no code stopped and you'll see here I had to go in and script pulling those values the the rub is that I could find out is the the rest or the rest message I'm getting from bitbot Market has an array of objects twice in this particular message that I'm looking at an array of changes that you can see there and an array of commits and this flow designer just kind of broke down whenever there was an array of objects even when I tried to do something like four each and loop through them so I knew that when I did this there's only going to be one commit when this with this web hook gets called so I just hard coded a zero in there that you can see right there where it says changes zero and commit zero and that's essentially just grabbing the first element of the array so I had to do that for the author I had to do that for the hash I had to do that for the link so this is where I feel like the no code kind of fell apart because I did have to come in here and write some code to actually do this there is one other place where I wrote some code too actually I didn't write it artificial intelligence did but that's actually creating the record then the artificial intelligence Parts comes in because I was like hey I need to extract that story number from the commit message and I didn't want this integration to say oh you have to put the story number at the beginning and there has to be a colon and it has to be done this way so I asked chat GPT hey can you give me the code for a regex that searches a string and extracts that number so chat GPT made this code for me I came in I changed a couple of things like it had string here I changed that to message and there you can see where I added in my data or my my Json object or complex object to pull in that message and then did the everything else the same so I had to tweak it a little bit of what chat DPT provided me but then once I had that I was able to look up the story number I'm given that number and then I was able to update the bitbucket commit record to go write that story number uh or to that particular record so that creates the link that makes it show up on the related list that you saw when I did that demonstration so that's how that particular flow is set up the last thing I want to show you here is I created this in a scoped application called bitbucket and agile teams so the other things that are missing there that we wouldn't have known is that bitbucket commit table I also have a specific form or view on the story view let me go back to that so you can see there I share this instance with other people so I didn't want to mess up the view for default view or something else so I made a view called bitbucket and on that bitbucket view we show this commits related list so I'm just being courteous of the other people that might be using this particular instance that I'm using so other things in that particular application there's a default view on the bitbucket form there's the flow for the web hook there's where I was doing some testing and I well that looks like one of my demos got associated with this application and it has some security associated with it but that's essentially the how simple it was I mean literally created a table and my flow I was expecting it to be a little bit longer but four steps in a flow and yes yes I did have to do some screen scripting I basically figured out for the first one and then copy pasted for the cut last four and then I was lazy with the regex part I didn't really want to go figure out the regex myself not a big fan so I asked chat GPT and it came back in a couple of seconds I tweaked the code made sure it looked right and matched best practice and that was it I was done so that's how the integration between bitbucket and servicenow works in my particular instance I hope you found this video helpful if you did please like Please Subscribe or share it with somebody who you think might be interested in writing their own Integrations between servicenow and other applications and until next time don't forget to always be learning foreign [Music]
https://www.youtube.com/watch?v=gVxWkadl8vg