Jenkins configuration with remote live server - jenkins

I want to know how to configure Jenkins with my live preprod instance server ?
Let me to explain you my process and tell me if I'm right and if that's not the good way to do.
1) I have my project project-1 in a server: /var/www/preprod/project-1, this project is in Magento Cms so it contains many files.
2) I copied this project project-1 in a repo Git, repo = project-1.
3) I cloned this project from this repo Git to my local machine: MAMP/htdocs/project-1.
4) I installed Jenkins, and I configured it with git, So when I do some push, Jenkins do a build automatically.
Now what I want to do is after the build, I want Jenkins to upload these changes to my live preprod server, whether automatically and manually.(I want to know the method to do it manually and automatically).
With this method, I develop in my local server, so when I finish some task and it's done, I push it to Git to have the changes history, and after that my need is to push it to the live server.
So tell me please if I'm using the right method, if it's a good practice and what I miss for this continuous deployment & delivery.

You can push it to the server using the Publish over SSH command if your doing a freestyle job https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin, If you are doing an pipeline then you can do a simple scp command...
you can run this after the build is completed and it will run it automatically for you ...
Manually you will be notified when a build is done then you would copy it into your server using the normal way you would do it i.e.copy and paste...
Jenkins is a automation server. The whole point of using jenkins is to automate things so that you "manual" intervention is not required. So automate it where ever possible.
Hope it helps :)

Related

Triggering CI builds using Jenkins on remote build machine

I am trying to implement CICD with Jenkins. I have my code in git repo. The moment I make a change to git repo files, I wish to trigger a Build that should run on remote machine.
This means If I change a file in Git Repo 10 times, I should have 10 Builds, each build corresponding to one change.
Can anyone tell me how this can be done ?
I tried to make use of post-commit hook, but its not working.
What flavor of GIT? Do you use? If you share you config details of webhook and Jenkins additional info can be provided. Per my experience it is a two step process.
Enable the webhook in GIT
Create a job with appropriate configuration to map to the repository and get triggered on commit

Deploy web app via Jenkins

I have recently started to mess about with Jenkins and am unsure how to deploy my web app to a basic server. I've gotten into the Pipeline (https://jenkins.io/doc/book/pipeline/) and it seems like a fantastic way to work.
Where I'm a bit stuck is in two spots:
Once my repo is in my workspace within Jenkins, how do I prep it so I am only deploying the files necessary for the application? For example, I don't need my src/ directory or my Vagrantfile when I'm deploying things.
How do I deploy my app to the server? I see examples all over the place, but I am getting a bit lost since there seems to be so many ways to do this. I'm assuming scp or something like that...?
To build off of #2, is there a way to deploy web apps as transactions (in one shot) rather than file-by-file?
Please let me know if I can provide any information for potential answers!
I can't speak to your specific use case but a common way to do this is the build-and-deploy model, where you will have 2 Jenkins jobs. The "build" job will check out from source, run build commands such as maven or make, and lastly will "archive" the build artifacts. The latter is an option under the 'post-build actions' tab at the bottom.
In the "deploy" job, you will grab the artifacts of your choice. You can fetch a single file, all of them, and everything in between. This requires use of the 'Copy Artifact' plug-in and it allows you to copy files generated by other jobs. Now you can run your usual deploy script in the 'Execute Command' box. Most command line paradigms are supported out of the box such as setting environment variables.
The instructions above assume that you want to run your application off of a host that you've provisioned as a Jenkins slave.
Use artifacts as mentioned by Paul Back, or a 3rd party artifactory server as in video
This is always tricky and error-prone. Why not spin up a fresh server with new release (humanly verified once)
Jenkins & Ansible is the answer here. This is how I deploy to production, since I am in no need to use anything like Docker (too many issues with particular app) so have to run the app natively. Quick example would be
You monitor a specific branch in gitlab / github or whatever else and then call a webhook on push / merge etc on that branch, at this point you deal with anything you need to do by running a playbook on the jenkins job that monitors that branch (jenkins).
in my case jenkins and ansible run on the same server. Jenkins runs the ansible playbook that does whatever I need to do.
for example with ansible, I copy certain files that need to be there, run configs / change filenames etc. setup nginx, run composer,
you get the point.

Using Jenkins for Continuous Deployment of WebApp - Publish Artifacts to Server

We are searching for a CI and CD Solution for our WebApp based on NodeJS/Meteor.
Our Process should be:
On each Push to Master/ Pull Request/ Merge to Master do the following:
Checkout
Run Code Style Checks (coffeelint, scsslinter, etc.)
Build Code
Run Tests
Generate Tarball-Archive
Deploy archive to Developmet (Quality Management) Server, extract and run
next step would be manual testing of the app on our dev server.
when we think it is deployable, I want have a button in jenkins like "Deploy these Artifacts NOW to Live-Instance". How can I achive this? Also Nice would be something like deploy these artifacts at 2am to the live instances.
From Checkout to deploy to dev-server is already implemented in jenkins. What we need now is a button "deploy this artifact to live"
You need another job to get this working. The other job takes the artifact from the build job and deploy it wherever you want.
There is no possibility to include such behavior in the same job.

Trigger a new build via Codeship API from Jenkins

I have a CI/CD setup with a Jenkins server to manage our internal CI/CD. We have Codeship performing our CI/CD for our AWS work.
I'm looking to setup jobs on our Jenkins server to manage when new builds are triggered on Codeship.
The aim being, we will have our Jira dashboard integrated with Jenkins in such a way that as an issue's status changes, specific jobs are executed.
So I'm trying to create a job that uses Codeship's API to trigger a new build, but it appears that you can only rerun an old build? How do you trigger a fresh build?
From the docs enter link description here you can only retrieve information and restart previous builds.
You want to run specific jobs, but those must be associated with some specific commit on your repository. You can identify the build for that specific commit and restart it.
Builds are always triggered from your git repository (github or bitbucket), and Codeship is highly dependent on that to keep the flow as simple as possible. You don't need to upload anything anywhere and then command Codeship to run a build on that. All you need is specify a repository and push something.
You could create an internal git server where your developers push to and with jenkins you can push changes from there to a repository connected to Codeship. That way you could control indirectly what gets tested and what does not.

Promoting the affected file to remote server

I work on web app.
The file in my development environment that contains changes are pushed to perforce.
In order to deploy the development changes to qa server, I used to manually copy the affected files(perforce commits) from development server to qa server.
Now, I am planning to use Jenkins. I am using Jenkins plugin to hook up perforce changes. Whenever Jenkins build is triggered, all the perforce changes are detected by Jenkins job. As soon as the build runs, I want to run a shell script that copies the affected files of perforce to qa server.
I went through the docs, but there is no way to fetch the affected files of the build.
Can you recommend me the way to copy the affected files of build to qa server?
Do you use Perforce replication at all? Perhaps a 'Build Farm' or 'On-Demand' type replica server would suit your needs and would thus copy the changes over for you.
Otherwise, on a Unix OS a command like 'rsync' can be used to copy files from one location to another.
REFERENCES
Admin Guide - Perforce Replication
http://www.perforce.com/perforce/doc.current/manuals/p4dist/chapter.replication.html
http://answers.perforce.com/articles/KB_Article/On-Demand-Replication

Resources