I am looking for a Jenkins plugin that makes it execute simple shell script into a given machine.
A possible execution of this plugin would be:
Given hostname,username,password, execution folder, and script --> connect to the machine and execute the script.
Can I do it without pre-configuring the machine as Jenkins slave?
I've checked out ssh-plugin and publish-over-ssh but they don't offer doing such thing without preconfiguring the hosts.
So I couldn't find the right built-in solution for Jenkins but Python Fabric is an interesting direction
Related
I've been trying to debug this issue all day with no success.
Issue: Bash script executes successfully on a Linux CentOS7 VM (jenkins build agent) but fails during Jenkins build.
Here's the simple script.
#! /bin/bash
echo "before beyond compare command"
bcompare #"bc_report.ps1" "./Output_Base/<Folder_Name>" "./Output_Compare/<Folder Name>" "Report.html"
echo "after beyond compare command"
The output in the Jenkins build log is just:
before beyond compare command
after beyond compare command
When viewing the VM during the Jenkins build, I'm not seeing an artifact being produced. The user during the Jenkins build is Root, when executing the script locally, I'm also doing so as Root with success.
I'm pretty sure this is a Jenkins issue, just can't seem to figure it out. Anyone seen something similar?
Beyond Compare 4 for Linux requires an X-Window/GUI session to run, even for scripts. As a cron job or in an SSH terminal without an X-Window client, Beyond Compare for Linux scripts will fail to run. This might be what is causing your Jenkins job to fail.
Beyond Compare 4 for Windows doesn't have the GUI session requirement for scripts. Beyond Compare 4 for Linux and macOS both require a GUI session for scripts. Removing the GUI session requirement for scripting on Linux and macOS is on the feature request list for a future version.
I went through Get Start Guide and api_request_doc to find a way to execute a script when start a microVM? But there is not way to do it.
Is there a way to achieve it? I want to run some script when a vm startup or execute a script without login.
So, far firecracker has not provided any support to start a script on startup.
You can use system daemons like openrc (for alpine based) and systemd to start the script on the startup.
to start script using systemd on startup, check https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux
Am looking for the best & proper method to execute script on remote via Jenkins job.
What is better:
Write the commands directly on the Jenkins "Exec command" label on the "Send files or execute commands over SSH" tab.
Just copy a bash file to the remote and execute it through Jenkins "Exec Com.." label command.
The reason I'm asking this question is because I am struggling with the second approach (i.e. execute local file which located on the remote...) and thinking maybe that not the best practice.
In addition, should I execute the script using sudo (because running as sudo causes me gitlab issues when try to clone..).
And when I am execute the the script he ask for password.
So far added permissions to /etc/sudoers not do the job but I'm thinking maybe that's a tab/lines issue...possible ?
Any suggestions ?
I personally would go for SSH protocol approach (Simple, secure and reliable). Moreover, there are some plugins already made for those use cases you've mentioned.
1. SSH plugin
You can use the SSH Plugin to run shell commands on a remote machine
via ssh.
So this plugin would fit into your first option of executing script or commands on remote via SSH.
2. Publish Over SSH Plugin
The goal of the Publish Over plugins is to provide a consistent set of
features and behaviors when sending build artifacts ... somewhere.
The Publish over SSH plugin will allow you copy files to a remote server and execute arbitrary commands on the remote server. So this fits into your second approach where you want to first copy script and then execute.
Really you can use any of those plugins (Both use SSH so it's more secure). The question is what suits you the most. Choose wisely :)
Which puppet module to used (How to configure), so that it can execute command in the remote machine, without using any puppet agent
for example from HOST-A, a puppet script to be executed and it takes the command and execute the command in HOST-B
what i know is the openssh keys can be used to exchange the login info, then after the command can be executed, what i'm missing is is there any module available that do this job, so that, just adding the command the same can be achieved
This is coming from the ANsible background
You maybe looking for mcollective/live management feature of puppet which allows you to run ad-hoc commands on the nodes. However you will have to install mcollective agents on all the nodes being managed any ways.
If you compare it with Ansible, puppet does not support running ad-hoc commands inherently otherwise. It does not work over ssh like ansible does. Its not agentless by nature. You need puppet agent/apply to be installed and configured.
There is no built in way of achieving this, but you can use exec to execute ssh with a command to run on another machine. The command to execute would be the same as what you would use from the shell.
you need jump out from the pit what you know about Ansible when thinking of puppet, they are different.
Puppet works for final status called idempotency, ansible is as batch ssh scripts.
The rest, #Gourav has been explained clearly.
I'm new to this area and was trying to run the following commands from jenkins:
npm install
grunt quickStart
So far I've a jenkins running on a window machine as a window service and I've also installed NodeJs plugin for jenkins.
However, I'm stuck and quit confused following instructions here, its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place.
Here is the bit that's asking me to do:
I cannot see this setting for the jenkins job I create. Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine.
Note : I've already checked out a project using git in jenkins!!!
Thanks
"its asking me to to add one or mode nodeJs installation and I could not find those setting and not even sure if I even need them in the first place."
I don't think you need that I have pointed jenkins to the node installation folder an nothing more.., for this you go to Manage Jenkins->Configure System->NodeJS->NodeJS installations.. type in any name you like and point to where the node home folder is.
...cannot see this setting for the jenkins job I create...
Once you have configure that in your jenkins configuration you should have that configuration available like so:
...Is there an easy way to run those command in jenkins from a .bat or .sh script, a .bat would be recomended since I'm on window machine
I'm sorry don't get what commands are you referring to...
so summarizing :
you have to tell jenkins where you have your node installation
use that configuration in your jobs
hope this helps...
The way I made it, was trough execute shell, as the build tool for nodejs is npm, I simply wrote a shell script that instructs jenkins to run npm install in the workspace directory inside jenkins where it clones the git repository and then to zip and move the package if successful to another folder.