Zero to Jenkins - PHP Continuous Integration

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Learning how to this set up was a real chore but everything it does/can do is awesome and totally worth it. Hopefully the video will get you started setting up Jenkins and illustrate where Jenkins can fit into your development process.

👍︎︎ 3 👤︎︎ u/trymuchharder 📅︎︎ Sep 24 2013 🗫︎ replies

Seems good, unfortunately I don't have time to watch all 48 minutes this week, but hopefully this weekend I can watch it!

👍︎︎ 1 👤︎︎ u/Ogsharkman 📅︎︎ Sep 24 2013 🗫︎ replies

Thanks for this. I've been meaning to set up some CI environment for our internal product development for quite some time to make things a bit more "professional". This video gave me a great starting point for figuring this out for us.

👍︎︎ 1 👤︎︎ u/teel 📅︎︎ Sep 25 2013 🗫︎ replies

Hmm, seems interesting. I will watch it next week :)

👍︎︎ 1 👤︎︎ u/zuzuleinen 📅︎︎ Sep 28 2013 🗫︎ replies
Captions
yes so a couple days ago or lately I've been seeing a lot of posts about Jenkins and for continuous integration and building PHP projects and that didn't really make sense to me since you just usually throw some PHP files on a server and you're good to go I didn't understand the whole build process so that intrigued me and I also didn't quite understand once I learned what Jenkins could do I didn't understand where it fit into the development process and so I asked a quite I've posted a text post on Reddit and got some good feedback and so I decided to to start playing around and I set up Jenkins after that and it's a pretty painful process for a beginner so this is my attempt to start from scratch and show you the steps I've taken to get everything set up so the first thing I did was go to puffit and I'm using digitalocean - the host Jenkins and so I click on a digital oceans tab and then if you run into problems getting a VM set up with digital ocean I recorded a previous video showing the problems I ran into in the solution I came up with so I encourage you to go watch that but anyway I'm running going to precise and then you input your your API credentials and then the I'm running engine X in my sequel and then the another important part is well past it the PHP extensions one of the build tools uses a PHP 5xs cell so make sure you have that it's a whole lot easier to let puffit and vagrant do it and all it for you then to do it manually so do that and then once you got the VM booted up you can start installing Jenkins so this is what I have here this is my fresh freshly booted VM I have nothing installed on it except what I define and puff it so the first thing I want to do is a do an apt get update update everything and then I want to apt-get install Jenkins why enter and then I should mention that I'm going to run into some problems I've it's a it's a kind of a lengthy process and there's a lot of parts to get wrong so hopefully you can I can get through those and can show you what I've learned but once Jenkins is installed you should be able to go to port 8080 on your on your VM and it should be a Jenkins should be a starting up so before the video I can show you but I just set up a hosts a line in my host record to point so this is my IP address to the VM and then I'm just pointing that to digitalocean dev just in case you see digitalocean dev in my up here in get confused super okay so I got Jenkins installed so it should be good to go if I go to port 8080 and there we go but we need to do some stuff first and this is the article that I saw posted to Reddit and I followed its directions and got the skeleton project to build and saw what all Jenkins could do and thought it was really cool but I couldn't figure out how that would work in a real development cycle because I guess it assumes that you're going to SSH into the VM and get issue a get pull and then manually build your project which it that's not very real-world and kind of I don't know the major advantage to having Jenkins is to get it automated so I'll show you what I did to get to get it automated but so we're not going to go by this step-by-step but we are going to we're going to take a lot from it so I've copied these commands out into my into just a blank document so they're because they're easier to copy out when you have the whole line so the first thing we want to do is I didn't copy this one copy this command and issue that in your VM and then I can get started with these which installs the plugins but okay so previously I've had trouble with that step and what you need to do if you do is go to manage Jenkins and then click on manage plugins and then go to advanced and then click this check now and then after it checks for the updates you can install you can reissue that command to install all those plugins and that's what I've had to do before but it looks like I didn't need to do that this time so and then now we need to well it says restart it but I'm going to just try to go ahead and I better not I'm just going to restart it restart Jenkins so now if you update this it should tell you that Jenkins is restarting yep and restarting Jenkins always takes takes a little bit so after we restart it it's telling us to install curl but puffit already installed curl for me so I don't need to do that and then this came and goes and grabs the PHP template which is what we want to use for our job so okay so Jenkins is rebooted so now we can go and copy that to grab the PHP template and we have that now and now we can restart it again and after after you install that template it says to go to to change the permissions for that template so if we go to VAR Lib Jenkins jobs list out we can see that PHP template right there and then we can do a CH own our Jenkins Jenkins the user in the group and pass it the template so that assigned it ownership so now Jenkins should be able to create and delete anything within there which I'm not so sure is the case because I've run into some trouble before but we'll see so now we need to go install the latest version so we're running 1.4 to 4.6 and there's a new version so what you need to do is click the download link and that will download a Jenkins dot war file and what you need to do is upload that to your to your VM so to do that you can use the SCP command which I have right here but you have to do it outside of your VM so you do SCP and then you point you give the path of the downloaded war and then your SSH connection info which is root and then at whatever your IP is that your VM is using and then you pass it where you want the war the dot war file to to be to get copied to so if I copy this and then outside of the shell so just from my computer I can do that and that will sell that will start uploading that that war that new version and it always takes a while but what we can do in the meantime is set up set up your your prot a sample project that that we can build so I have this Jenkins demo PHP project um set up to use so you can go and clone this and and test Jenkins out with this project and basically it's just a it's a fresh install of level and then I've added so in in this website this Jenkins PHP template website it has some sample build XML files and so basically we've copied this and then modified it slightly so in in here it points to source a lot and so I point that I point all those to the app directory and label so it's actually looking at code and building off of that but but other than that it's all pretty much verbatim I think and then I have I have all these extra files that each of the build tools rely on so that's what you'll see right here I got the main one and then a bunch of sub build files so what we can do is clone this let's open up a new window and then CD into someplace that we want to keep our little demo project so I'll just use a smile sites directory and then I'll clone it into a layer whole project directory and there I have it let's get rid of this and then open up sublime or a text editor editor of your choice and then let's CD into their CD layer whole project and then let's get checkout develop and now we're on the develop branch and that's important for for later and then we can so after you've clone the repository you can go in and create one for yourself so I'll call this level project and then your have some existing code to push up so you can do a git remote set URL origin and then pass it your get URL and then push all of it up you so now if you refresh this you should have a cloned a sample project that you can use with Jenkins with both aim at both a master and develop branch so then we got that set up get a little bit longer to wait for the for the new version go in here edit this just to make sure everything's synced up and working push origin develop around the develop branch and there we go so if we go back to the source should see the little addition that we made and if you haven't already if this is none of this is working you need to set up an SSH key which I show you how to do in in another video where I show you how to get lower hole setup in a in a VM so check that out if you get stuck it's a pretty simple process I'll even show you later because we're going to need to set up an an SSH key pair for our VM and bitbucket so they can communicate back and forth I've had trouble after I've uploaded this Jenkins dot war file because you need to restart Jenkins and I haven't figured out the smoothest way to do that because it there is a bunch it looks like Java exceptions whenever I restarted we might see that but hopefully not and if we do I think I know a way around it okay so now that that file is uploaded we can restart Jenkins so I'm going to try to do it this way then you and manually stop Jenkins well you know what might I might be able to get away with installing some plugins first see what happens if we click that okay manage plugins go we're probably gonna have to update them so we need to restart it yeah okay so if we copy this stop command or we might be able to do this just put restart in Alaska so if we're sure we'll say yes yeah okay that worked a lot a lot smoother than last time previously I've had to issue this stop command and then and then start it back up using that but it doesn't look like I'm I have to do that this time okay now so if we go yeah see now we're we were run in 1.4 1.4 to 4.6 I think and now we run on running 1.5 oh nine three so we're good to go so now I have some updates so I'm going to go install all of these just to be safe and then previously what I've done this it says it will restart because I clicked restart Jenkins when when updates are downloaded but and that's what I expect to happen right now but that's not happening so I'm not sure what the deal is with that but if we go to available and do a search on git plug-in and we want this one that's just titled to get plug-in right download that okay so now we have all our plugins downloaded but I don't think they're installed yet and you have to reboot it to get for those plugins to take effect and I think this is the part where I haven't had a graceful way to restart it because I think I tried that same trick just doing a restart here and I got a bunch of it exceptions thrown so I'm going to try this to manually stop it and restart it and we'll see what happens let's go refresh this you okay seemed to work out before we go any further though let's set up some security because right now anybody can access your Jenkins install and do whatever they want which is never good so if we go to manage Jenkins and then configure global security enable security and then we want to use Jenkins own user database and then we want to allow users to sign up because if you don't do that you'll get locked out of your own Jenkins which is not good and I've done that before so but we want to use matrix matrix based security and so if you use this anybody will be able to come to your Jenkins install and register an account but if you have this matrix based security they won't be able to do anything they can't get in or do anything so what you want to do is put the username that you're going to create in this field and click Add and then give yourself give this future user all access by checking all these boxes okay save that so immediately we're going to take it to this login screen because we just set up security and if you do end up locking yourself out I'll I'll post this link somewhere but what you can do is stop it stop Jenkins with this command and then use vim and go in and edit the config dot XML file and set the use security to false save that and then restart it and it will restart it in an insecure mode and you can go back and do it the right way I've had to done that I've had to do that but we want to create an account with the username that we just specified and once we do that we're back in and we have all access okay so now let's set up a job so let's go back to Jenkins new job and then you can name this whatever for this demo I'm going to keep with my level project name and then you want to copy existing job and you want to copy that PHP template that we downloaded click OK all right and now we're we have to configure our job so that get plug in put this section in so if we press the the get radio button and since we set up our project we can go to its home page and get its its URL and paste that in there but Jenkins doesn't have an SSH key pair set up with bitbucket so that's not going to work just yet so we need to go set that up so what we do is we change to Jenkins sudo su Jenkins and then we can go to CD into VAR Lib Jenkins and then we want to CD into SSH and then we want to create a key pair so we can do that by this ssh-keygen command - TRS AC and then your email do that and then it's going to ask if you want to save it - ID underscore RSA which is the default just push enter you do and then this is important you do not want a passphrase so don't enter in it or don't put anything there and just press ENTER and then press ENTER again and it will create it so now if we list out we can see our private key and our public key so we want to see what our public key is because bitbucket needs to know about that so we can Kat RSA dot pub and then copy this section our public key and then go to go to bitbucket managed account SSH keys and we want to add a key and this is my Jenkins key and you just want to paste it in there add that go back to Jenkins copy this out and then paste in it again though that should have worked mmm you know what we might need to do this SSH SSH - T get at bitbucket Borg yeah and then this is kind of to establish the connection push or enter yes and then it will tell you that she'll access is disabled which is normal that confuse me at first so now if we go do this it works there we go and then it asks for the branch we want to build so when I guess what's common is not to do your development on the master branch but create a develop branch and do all your development on that and then build off of that branch which I have done in my level project repo there are two branches the master and the develop so I guess I should probably back up and tell you what this is doing so whenever this build runs it's going to clone this repository and then run a bunch of of tools that we've downloaded using composer to output different reports and API documents and run our tests and a bunch of other stuff so and then down to the next section we want to build triggers and then authentication token can be whatever you want it's probably meant to be a random random string but I'm just going to use the word build for the for this demo and that's going to allow us to hit a URL jinkins URL and that'll trigger a bill to go off so we can hook bitbucket in to Jenkins to make those a to automate this we want to delete invoke ant and then add execute shell and then do a composer update and then we want to add another one and then if we do what we find it's the this we want to run thing which uses our build XML file to to do the testing and measuring and all of the build build stuff so we paste that in there and then leave all this the same and then here that this is an error in the PHP template because this is building this is publishing a row basically it just creates a link on your your project page that points to the API documentation that that that the bill generates and this direct this path is wrong what you want to point it to is build API slash HTML so change that and then save this and then you want to enable it and then before we go any further let's uh let's let's go change the the ownership of our of our whole project workspace so let's go to var Lib Jenkins jobs and then we see our level project in PHP template so you can see it own - our Jenkins Jenkins variable project enter now that we've done that let's build it well attempt to build it it's not going to work but we can see why by going to the console output yeah and it's complaining because it it doesn't is trying to add a tag oh via get and it can't without get knowing who it is so if we go to should have go back to here and then go into our there whole project and then get config user email and then pass it you're probably want to pass it the project owners email not sure it matters let's see maybe if we just do the global it might work hmm unknown option get oh did that wrong goes after config and then we could change this to Jenkins user name to Jenkins and then let's try it again build feels immediately again ok so this always breaks the first few times and I haven't figured out the correct way to do this but what you can do is CD into the workspace and then do a composer dump auto load and then you can poser install and this will take a while and what I found is if you skip this and keep trying to build it in the Jenkins GUI it's going to break because composer is trying to hit github too many times to to get vendor packages and so I found that you need to do it at least once through the terminal because it will prompt you with your github username and password and I think you need to do that too to set up that connection but what we can do in the meantime is set up our bit bucket hook so we can go to Jenkins manage Jenkins manage users and then click on the user you created and click configure and then click show API token and this is and then you need this to to hook into the to create a hook so now that I have that I can go click on my my repo this cog button over here and then setup a hook and then add a Jenkins hook and then your endpoint is is your username your Jenkins username the API token that we just copied and the IP address or if you've setup your domain name you can use that and then the port that Jenkins is running on so if we copy this as our endpoint and then our project name in Jenkins is a layer whole project this is in Jenkins not this one and then our token we specified as build so if we save that refresh this yeah ok so that should be set up so let's check where we are on this guy yeah ok so this is where it's asking me for my github credentials and I think you need to do that at least once okay so let's clear all that out and then let's try it let's go back to our let's go back to the Jenkins homepage click on the level project and then watch in this area and hopefully we'll see a build get queued up here so if we go back to your the project you've cloned and change something on the develop branch and then commit that so that one get commit - am testing build get push origin develop and there it is so I'm not sure if it will work or not but we can click on it click on the console and then watch it do its thing watch it attempt to build the project and what you're probably want to do is I because I think this hook that we set up it doesn't matter which branch gets committed to it will always initiate that hook it'll always ping our jenkins which initiates that build so what you'll probably want to do is point this to a PHP script served up by your VM and then because it will put its what it's doing is it's posting JSON to that endpoint and Jenkins knows how to interpret that so what you'll probably want to do is look at this the branch name and then based on that branch name issue a a post request - not that but not this URL but whenever you specified your build token right under that it showed you a URL that you could you could post or issue a get request - that would initiate a build so you'll probably want to do that because I don't think you'll want to build on every branch commit there we go it looked like it a it worked which is pretty amazing since I've had so much trouble with this in the past so if we go back to the project we have a blue blue ball which indicates this success and then we have all of this we have code coverage report we got let's say I think this is it measures your unit tests and then this is the link I was talking about that we fixed in our build if you clicked on this link before we fix it it would lead to a 404 but now you can see we have this our API documentation and these are just methods I put in there to to test the API generation which is it's just pretty sweet and that was done for us automatically because we specified that in our build XML which uses PHP Docs which is right here and then that looks for this file and so I pointed it to the the output - well we don't really care about the output that's already set up but for the source to look in the levels app directory and I'm sure there's probably some more similar things you can add to this to ignore certain files or only track only generate documentation for certain files but I just haven't explored that but that's really cool and then you can look at your your tests so we only had one test in it and it passed and then in your in your configuration you can set up post post build actions add post build action and you can set up email notifications to to uh to get fired off to warn you of a bad builds but I haven't explored that too much but that's one thing I want to test out is to figure out how to initiate a build and then have the the initiator of the build get emailed of the of the the fill the failed build but I haven't gotten that far but yeah that's pretty much it that's pretty much it kind of a long process but I think it's going to be worth it I think this is I think this is really cool but yeah hopefully that was clear enough and if you guys want me to I'll probably create a gist of some of the commands that I used but if you guys want me to I've been thinking about starting a blog to kind of document some of this these things that I've been trying out so if that it all interests you comment on the the reddit post or subscribe to the YouTube channel or something just let me know that that you'd be interested in otherwise I'm yet I'm just going to pass but if you guys want me to do that I've been meaning to do it anyways but that would encourage me but anyways I hope you learn something good luck with everything yeah we'll see you next time
Info
Channel: David Adams
Views: 36,239
Rating: 4.8216562 out of 5
Keywords: jenkins, php, vagrant, puphpet
Id: PklYO2vYIfc
Channel Id: undefined
Length: 48min 9sec (2889 seconds)
Published: Tue Sep 24 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.