Jenkins

Install Jenkins locally on your MAC machine

STEPS:

  1. Go to terminal
    • brew install jenkins
      • DNVCOML-6BZ8G3Q:~ user$ brew install jenkins
  2. After successful installation run this command
    • DNVCOML-6BZ8G3Q:~ umahaea$ jenkins --version
      2.156
  3. Jenkins is usually installed at this location, and lets start Jenkins
    • DNVCOML-6BZ8G3Q:bin umahaea$ pwd
      /usr/local/Cellar/jenkins/2.156/bin
      DNVCOML-6BZ8G3Q:bin umahaea$ jenkins start
    • Look for this message
      • Dec 23, 2018 7:00:35 PM hudson.UDPBroadcastThread run
        INFO: Cannot listen to UDP port 33,848, skipping: java.net.SocketException: Can't assign requested address
        Dec 23, 2018 7:00:35 PM hudson.WebAppMain$3 run
        INFO: Jenkins is fully up and running
  4. Open browser and type localhost:8080jenkins-1
  5. Get the password from the mentioned location, enter and proceed.
    • DNVCOML-6BZ8G3Q:bin umahaea$ cat /Users/umahaea/.jenkins/secrets/initialAdminPassword
      b6caab39aca74c5a92319ba5c606e966
  6. Create first admin user and continue
    • jenkins-2
  7. Set up the instance configuration and jenkins is ready to start
  8. Login with the user name and password and you are all set.
  9. If you see this error: :/, then don’t panic :), follow step 10
    1. There were errors checking the update sites: SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  10. Go to Jenkins -> Manage Jenkins -> Manage Plugins -> Advanced and update the upload site to http://updates.jenkins-ci.org/update-center.json
  11. And restart Jenkins, you are freed of errors and play around with building your software in CI mode.

 

Access variables in subsequent steps in Jenkins Job

PROBLEM:

How to carry over environment variables to subsequent build steps?It is possible by making use of a Jenkins plugin(which is not installed by default)

STEPS:

  1. Install the plugin:
  2. Go to http://your-jenkins-address/pluginManager/available1_moiZY0A7fc9zFVvTwZdlTw
  3. Determine which variable you want to be used in the subsequent build steps
    1. In my case I’m trying to use a variable called ipAddress which I want to pass it on to subsequent steps
  4. Create a properties file in your jenkins box
    1. login as a jenkins user
      • sudo -su jenkins
    2. Create an empty properties file and save it. I have used /var/lib/jenkins
      • /var/lib/jenkins
        • jenkins@ip-:/var/lib/jenkins$ vim your_file_name.properties
  5. Lets go back to Jenkins Console -> Job
  6. In the Execute Shell, write this step
    • echo “ipAddress=your_value” > ~/your_file_name.properties
  7. You should be able to add a Inject environment variables step only when step #2 is success
  8. inj
  9. Pass on the properties file path, this will pull all the variables from the properties file and allow it to be used in subsequent steps:
  10. Screen Shot 2018-08-08 at 4.10.10 PM
  11. Try to read the value of $ipAddress from a subsequent execute shell step
  12. Screen Shot 2018-08-08 at 4.20.43 PM
  13. Run the jenkins job.
    • You will be able to see this step printing the ipAddress value.
    • When you cross check in the jenkins box, go into
    • jenkins@ip-:/var/lib/jenkins$ cat your_file_name.properties

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s