logo

NJP

Modeling the Jenkins scripted pipeline with Devops

Import · Mar 03, 2021 · video

this video shows how to model the jenkins scripted pipeline in devops from preliminary setup tasks through verifying the jenkins integration setup you can skip to any of these topics from the youtube description for this video here are the prerequisites for modeling the jenkins scripted pipeline in devops if you haven't completed these tasks the setting up the devops connection for jenkins video will guide you through that process [Music] each app in your devops environment is associated with one or more devops pipelines a devops app is the item being worked on in this case our bicycle rentals app the work is done via commits to a code repository a devops pipeline is a set of steps that your code changes go through to make their way to production these steps are mapped to pipeline jobs or stages we're going to map pipeline tasks from a jenkins file to specific steps in our app a jenkins file is a text file checked into source control which contains the definition of a jenkins pipeline we start by setting up our application to manage in devops to do that we'll be going back and forth among our servicenow instance jenkins and our code repository github so we've got them all open in browser tabs the sm devops admin role is required to perform this task on the servicenow side we create a new app for bike rentals and name it accordingly after we save it additional form sections appear if we were connected to a planning tool such as jira we would map it here but we aren't so we'll skip that in the repositories section we click edit the collection list shows repositories already discovered for github we just select the one we want to tie to this app and save it before setting up our devops pipeline we need to take care of a couple of preliminary setup tasks first we'll need the credentials for a user defined in our instance with the ability to access servicenow devops from jenkins there's a predefined user in the system for this purpose devops integration user you can create a new user if you prefer that user must have the sn devops integration role we make note of the username and password which we'll need later also in this example we want our deployment orchestration step under change control so we need to make sure there's an appropriate approval group to handle that done now we'll perform some configuration in jenkins to integrate with devops here's the information we need note that field values are case sensitive this is the url of our servicenow instance it must be in the format shown here we'll get the orchestration tool id from our instance it's the sys id of the orchestration tool we created in the previous video [Music] so we open that record right click the form header and select copy sys id [Music] then we come back to jenkins and paste it here we enter the credentials the username and password of our devops integration user which we noted earlier and finally we test the connection which was successful so we save this configuration now let's take a look at our jenkins file it should be at the root level of the repository as shown here each root level stage configured in the jenkins file is discovered as a separate orchestration task in devops that's mapped to an individual step in our case they're build test create artifact for prod and deploy so this is the pipeline we'll be executing and these are the steps within the pipeline in the jenkins file if there's a change control step that requires approval the service devops app pauses the pipeline now that we've examined the pipeline on the jenkins site we need to model it in servicenow devops here are the steps to accomplish that link the pipeline to an app track the pipeline run the pipeline to create and map pipeline steps in devops set up change control in devops let's get started with linking the pipeline to an app we return to our bike rentals app it's already connected to our code repository so now we need to link the jenkins pipeline to our bike rentals application and here's how we do that okay that looks good let's take a look at the pipeline the value in this orchestration pipeline field came over from our configuration in jenkins and it exactly matches the name we gave the pipeline in jenkins this is critical for the pipeline to work it could be an issue if the jenkins pipeline was configured manually in devops meaning not discovered by the devops app in that case double check that you've configured this field to exactly match the name of the pipeline in jenkins to track the pipeline we select the track checkbox so that events from the pipeline are received the track checkbox must be selected to integrate the pipeline with devops next we run the jenkins pipeline to automatically create and map pipeline steps in devops all of the pipeline stages must be green to proceed there can be no errors here are our steps which mirror the stages in the jenkins pipeline you may recall that in our jenkins file the deploy stage notifies change control in devops so on the corresponding step in the devops step record we need to select the change control checkbox and the type and change approval group fields become mandatory we select our approval group which is already set up in the instance and the change type these types are explained in the product documentation we'll select normal and update the record the orchestration stage names must match those in the jenkins file now our pipeline setup is done to verify our jenkins integration setup let's go back and click build now this can take some time but we see that the job is going ahead as expected we can check on the status of stages like this the deploy stage creates a change request so let's check what's happening in our servicenow instance here we see that the jenkins pipeline is directly syncing with this pipeline ui the sequence of steps looks correct the system has created a change request as a result of this sn devops change line in the jenkins file and this checkbox in our deploy step but the pipeline is blocking this last step deploy because it's waiting for change approval so we'll go into the change request and approve it [Music] our change request requires two levels of approval yours may not when we look at the jenkins pipeline build history console output for this job we see this line which says the job is under change control and this icon usually means the job is paused this is because in the servicenow change request we need to implement the change doing this notifies jenkins to proceed with deployment and here in the jenkins build history console output we see that the job was under change control it was approved for execution and the pipeline finished successfully and back in our servicenow instance we see that the deploy step is complete [Music] for more information see our product documentation knowledge base or podcast or ask a question in the servicenow community

View original source

https://www.youtube.com/watch?v=RbC5mvLU5lw