Display run-time logs in jenkins

Hi,

I want to initiate chef-client cmd from jenkins and display runtime logs. Any idea how to do it.
server: ubuntu
client: Windows

Regards,
vagga

Hi @vagga06

You can SSH to the chef-client from Jenkins and run chef-client command using SSH plugin. I believe there is no other way around.

or you can try this link.

hope this would work for you :slight_smile:

Regards,

Waseem A

Hi,

We tried bot approaches and the SSH one did work better for us. We also had to redirect the stdout so chef would not write to the log file with chef-client --logfile /dev/stdout but I don’t know how this could be done on Windows.

Hi,

Thanks for your suggestions :slight_smile:

@waseemahammed: we are using multiple windows 2012 r2 servers as clients, to run chef-client command using SSH plugin we need to install and configure ssh on all nodes.
We donot have privileges to install and configure these tools.

chef-plugin is not available in jenkins, i can see the below plugin,
https://wiki.jenkins-ci.org/display/JENKINS/Chef+Sinatra+Jenkins+Plugin

no idea how to install the dependencies.

Regards,
Umesha

@vagga06 : Yes there are dependencies and limitation while using Windows server as clients. I never came across with these situations since I work more on Linux and less on windows.

What I suggest is you can use RESTful APIs instead of installing SSH on clients.

You can follow this link Chef Server API¶

Jenkins HTTP Request Plugin - https://wiki.jenkins-ci.org/display/JENKINS/HTTP+Request+Plugin

Or else invoke a PowerShell script to run chef-client against the node.

I have no other idea, you may give it a try. :+1:

Redgars,
Waseem

Hi @waseemahammed,

Thankyou :slight_smile:

I will try it out and let you know.

Regards,
Umesha

Hi,

created jenkins slave on nodes to get the runtime logs, but when i execute the command or bat file from jenkins (execute windows batch command or powershell) i am getting below error, any idea

F:\Build\jenkins_slave_workspace\workspace\chef-build>chef-client --once --force-formatter -o "recipe[Hybris-Backoffice::predeploy]" 
Starting Chef Client, version 12.16.42e[0m
resolving cookbooks for run list: ["Hybris-Backoffice::predeploy"]e[0m
Synchronizing Cookbooks:e[0m
  - Hybris-Backoffice (0.1.0)e[0m
  - windows (1.44.1)e[0m
  - chef_handler (1.4.0)e[0m
  - Windows_Service (0.1.0)e[0m
  - Java1.8 (0.1.0)e[0m
  - push-jobs (3.2.2)e[0m
  - runit (3.0.3)e[0m
  - packagecloud (0.2.5)e[0m
  - yum-epel (2.0.0)e[0m
  - compat_resource (12.16.3)e[0m
  - chef-ingredient (0.21.2)e[0m
Installing Cookbook Gems:e[0m
Compiling Cookbooks...e[0m
Converging 14 resourcese[0m
Recipe: Hybris-Backoffice::predeploye[0m
  * env[ANT_HOME] action delete
    e[0m
    ================================================================================e[0m
    e[31mError executing action `delete` on resource 'env[ANT_HOME]'e[0m
    ================================================================================e[0m
    
e[0m    WIN32OLERuntimeErrore[0m
    --------------------e[0m
    (in OLE method `delete_': )
e[0m        OLE error code:80041003 in SWbemObjectEx
e[0m          Access denied 
e[0m        HRESULT error code:0x80020009
e[0m          Exception occurred.e[0m
    
e[0m    Resource Declaration:e[0m
    ---------------------e[0m
    # In C:/chef/cache/cookbooks/Hybris-Backoffice/recipes/predeploy.rb
e[0m    
e[0m     11: env 'ANT_HOME' do
e[0m     12:   value "#{node['Hybris-Backoffice']['path']}\\hybris\\bin\\platform\\apache-ant-1.9.1"
e[0m     13:   action :delete
e[0m     14: end
e[0m     15: 
e[0m    
e[0m    Compiled Resource:e[0m
    ------------------e[0m
    # Declared in C:/chef/cache/cookbooks/Hybris-Backoffice/recipes/predeploy.rb:11:in `from_file'
e[0m    
e[0m    env("ANT_HOME") do
e[0m      action [:delete]
e[0m      retries 0
e[0m      retry_delay 2
e[0m      default_guard_interpreter :default
e[0m      key_name "ANT_HOME"
e[0m      value "F:\\Hybris-Back-Office\\hybris\\bin\\platform\\apache-ant-1.9.1"
e[0m      declared_type :env
e[0m      cookbook_name "Hybris-Backoffice"
e[0m      recipe_name "predeploy"
e[0m    end
e[0m    
e[0m    Missing Windows Admin Privilegese[0m
    --------------------------------e[0m
    chef-client doesn't have administrator privileges. This can be a possible reason for the resource failure.e[0m
    
e[0m    Platform:e[0m
    ---------e[0m
    x64-mingw32e[0m
    
e[0me[0m
Running handlers:e[0m
Running handlers complete
e[0mChef Client failed. 0 resources updated in 07 secondse[0m
Build step 'Execute Windows batch command' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE

Hi @vagga06,

It's clearly mentioned in the error "Missing Windows Admin Privileges".

I think this is because of admin rights. If you solve this error, then your chef run will be completed without any error.

Cheers,
Waseem

Hi @waseemahammed,

How to execute chef-client cmd from jenkins in client machine, help me pls.

Regards,
Umesha

Hi @vagga06
Are you using the Domain admin to run the chef-client over win2012 server? Make sure the account you are using has domain admin rights and not a local admin.

Hey @vagga06,

To do so, you can use knife winrm. Here is how you do it.

Or else you can follow the following topic thread,

I believe your sever is on Linux. And in order to run it through Jenkins, you can command your Jenkins to run knife winrm command on your chef workstation. :slight_smile:

Hope this is helpful. :smile:

Cheers,
Waseem

Hi,

It was issue with the user permission. I ran the jenkins slave with localsystem user then it worked :slight_smile:

thanks everyone :slight_smile:
Umesha