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.
Related
I have a user interactive shell script that runs successfully on my Linux server. But when I try to run it via jenkins, it doesn't run.
I have created a Jenkinsfile.
Jenkinsfile
node('slaves') {
try
{
def app
stage('Remmove Docker service') {
sh 'sshpass ssh docusr#10.26.13.12 "/path/to/shell/script"'
}
}
}
Shell Script
#!/bin/bash
read -p "Hi kindly enter the api name : " api
docker service logs $api --raw
The shell Scipt runs successfully on my local server, when I try to run it on Jenkins using Jenkinsfile, it doesn't accept $api variable in my shell script which is user interactive.
What you are trying to achieve doesn't serve any purpose of automating your job by jenkins, if I correctly understood. So, your job is actually seeking a user input and it's in best interest to have a parameterized jenkins build in this case.
For your case, you can still give an argument to the sshpass command $api and have it read from the jenkins environment itself Or, better make your jenkins build parameterized and use your user input $api as the parameter.
According to the documentation of the bitbucket plugin for Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/BitBucket+Plugin) it should be possible to access the payload infos through the environment varaible $BITBUCKET_PAYLOAD.
However when in my build I run the command printenv, there is no environment variable called $BITBUCKET_PAYLOAD, and nothing related to it.
So it's impossible for me to access informations I need to configure my build.
You can trigger Jenkins with Generic Webhook Trigger instead.
Then you can create a variable everything having the JSONPath $. Then everything will resolve to the entire JSON payload. So you can have a shell script build step like:
echo $everything
I have a few build scripts which can be run from the command line. I'd like to have a web UI to run them and I thought about using Jenkins. I see that the Jenkins job supports parameters and then defined parameters are set as environment variables in the build environment. However, I would not like to have to alter my scripts to accept input from environment variables, it would be easier to continue to accept input from command line. I thought about adding the following shell command to the Jenkins job:
eg <build_script> --option1 $JENKINS_PARAM1 --option2 $JENKINS_PARAM2
Then, I would not need to alter my existing build scripts. Is that a common/recommended usage of Jenkins?
Yes, This seems to be perfectly fine for me.
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}.
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.