Jenkins: using parameters in command used by ssh - jenkins

I am trying to build a generic job that connects to a server and executes command.
I use the "Execute shell script on remote using ssh" job. The commands are taken from a "Text Parameter"
If i don't use the parameter but write the commands in the "Command" field, they are executed. However, when i use the parameter, ${SOME_COMMANDS}, the commands are not executed.
Should there be a way to use the text parameter in the command field?

I don't think you can use a parameter directly in the command field, but you could get around it by calling a shell script with a fixed name in the command field and then having the script dereference the SOME_COMMANDS variable.

Related

Passing env/params values to the Shell Service plugin of Jenkins

Shell Service of Jenkins plugin is like in the picture that is below. I need to pass params/env variable to it but couldn't make it.
Is there any way to pass values into "Execute shell script on remote host using ssh"?
If this plugin works as a usual ssh command, you can escape $DOCKER_REGISTRY quotes
ssh jenkins#192.168.13.156:22 "echo \"$DOCKER_REGISTRY\""
IMHO: Get rid of the ssh plugins in Jenkins, just use shell, is way more flexible.

In Jenkins, How can I pass Job parameter values to a shell script which runs inside 'Check job prerequisites' section?

In Jenkins, How can I pass Job parameter values to a shell script which runs inside 'Check job prerequisites' section?
In the attached image, as you can see I am executing a shell script in the jenkins job's prerequisites part but want to pass a few job parameters to the shell script. But not able to do so, since jenkins doesn't recognize these parameters in prerequisites section.
Try removing sh from the command.
Verify if the relative path provided is correct. Click on "?" to see how this option really works.
The variables you are passing, are these environment variables? Check if Jenkins recognizes these variables.

how to pass a value to a property file from jenkins

I have created a Jenkins job to run the automation scripts.
I am using config.properties file to pass the input parameters to run the script.
My config.property file contains below :
browserName=ie
url=http://google.com
Is it possible to set the above parameters from Jenkins job?
Is it possible to do like below :
browserName=${BROWSER_NAME}
url=${URL_NAME}
Can i pass "BROWSER_NAME" && "URL_NAME" value from Jenkins job. if yes, then how?
Please suggest. I am new to Jenkins job configuration.
what you can do, is inside your script file, change it to take parameters,
after that, in you job, you can add a parameters, to be filled by the Jenkins form like "Build with parameters"
Finally, in your run script shell window, add the command to run your script plus the paramters you have filled exemple :
==> $PARAM_ONE (param job jenkins);
script.sh $PARAM_ONE
Good Luck
Like Hatim said: "change your script to take parameters" and pass params to your shell script.
But i suppose you want your script to access config.properties and config.properties must be filled with jenkins params?
if so, then you can just echo your jenkins params to this file directly.
Set your params in jenkins.
If you want to use complex config than your approach is ok and you can execute shell to insert params from jenkins to a file simply by echoing them and then start your script:
But if your config.properties is so small, you'd better use script params to make your build config easier. To do that you should modify your .sh script to take parameters from jenkins:
browserName=$1;url=$2
And then just add your params in execute shell:

How to pass parameters to Hudson job's shell commands

I have a Hudson job that execute shell script on a remote server.
Its shell command is:
/usr/bin/deployWar.sh ${warfileName}
I marked this build as parameterized, and added a string parameter:
name: warFileName
default value: none
description: name of war file
When I run it, the parameter gets assigned, but it get passed into the shell script.
Parameterized Build Jenkins plugin documentation states that
all the environment variables added by parameters are in upper case
In your case this should work:
/usr/bin/deployWar.sh ${WARFILENAME}
There is nothing wrong in your approach. How do you know it's not passed to the shell script? The console log will show the "execute shell" command line.
Please paste the whole console log in here
For me the accepted answer did not work. ${WARFILENAME} using the brackets did not find the parameter. The way it seems to work only for shell scripts execution in Jenkins is $WARFILENAME (without the brackets).
This tutorial helped.
Everywhere else in jenkins options used ${WARFILENAME}.

Can't access build parameters in excute shell in jenkins

I'm trying to call a python script through an execute shell step in a Jenkins parametrized build. The problem is I need to pass the build parameters to the python script which doesn't happen. Here is how I call the python script in execute shell:
python2.7 C:\test\my_script.py -m $module
$module is passed as an empty string.
I've tried in Execute Windows batch command with %module% and it worked fine.
But I need to run it on an excute shell not a windows batch command.
It looks like you are running on Windows ("C:\test\my_script.py ..."), so "Execute shell" will not work properly.
Should either use Execute Windows batch command or move your job to a Unix/Linux machine (can use a Jenkins-Agent for that).
Try this
python2.7 C:\test\my_script.py -m $MODULE
From the documentation
Note that because of the case sensitivity difference of environment
variables in Windows and Unix, all the environment variables added by
parameters are in upper case.
Hence please try using $MODULE instead of $module

Resources