I am using the BUILD STEP "Execute shell script on remote host" and I'm injecting a password to my project:
The jenkins call a script.sh, but the script does not print variable PASS passed by jenkins.
As a step variable issued by Jenkins to my external script?
PASS=${PASSWORD}
echo PASSWORD=$PASS
sh /root/script.sh
You need to export your variable in order to make it available to subshells:
export PASS=${PASSWORD}
If you don't want other programs you invoke in the same script to see your password, consider this safer way:
PASS=${PASSWORD} /root/script.sh
Related
I have a secret txt and want to pass the Variables in the Jenkins Shell script (Not the Pipeline)
Need help on this
withCredentials([string(credentialsId: 'API_TOKEN_ID', variable: 'TOKEN_VALUE')])
the above works in shell script inside the pipeline, but want to execute this in "Execute Shell" mode in Jenkins.
You may try this : https://plugins.jenkins.io/credentials-binding/
If it’s a token you can put it as an env variables
Following is a screenshot of how I am setting an environment variable in Jenkins.
I am trying to access it in a shell script, but it is not echoing its value.
echo "Starting ..."
echo ${BUILD_NUMBER}
echo ${DATABASE}
${BUILD_NUMBER} is a global env variable.
The correct use of variables in Jenkins is the following:
echo "The current build number is: ${BUILD_NUMBER}"
The important part is to use ". If you would use ' Jenkins would not notice that you want to access the variable and simply print your variable as string.
Source: Jenkins String Interpolation
I have a script called configAdmin.sh in remote node. I need to
invoke that script from local node, later it will open below session
and prompts for input.
some input like connect to domain
ConfigAdmin> -->
How can I achieve this through ansible?
To run a remote script that expects commands from standard input, you can use shell and provide the commands before your script with a pipe:
- shell: echo "some command" | myscript
I am trying to run a bash script from Groovy in Jenkins but I am not able to find the lucky commands.
I can run this and it creates my "RJ" directory:
process = "mkdir /app/jenkins/workspace/TEST/RJ"
println process.execute()
But when I try to run my bash it is not creating my output file. I am able to run this bash script on the server directly and it is creating my expected output file.
process = "/app/jenkins/workspace/TEST/info_file.sh"
println process.execute()
why run it through groovy and not directly via a ssh command.
If you do want to do via groovy, you'll need to add a ssh libray, and do the whole connection, auth, execute. process.execute won't run a linux box.
first, you don't check the stderr and not waiting for process to end.
similar problem was here:
Curl request from command line and via Groovy script
with error text it's easier to solve the error.
I'm trying to create a job in Jenkins that will execute a simple shell script. However, it seems that Jenkins isn't actually doing anything with my script. No matter what value I put into the Execute Shell Command section, Jenkins always says that it passes. Even if I put in a bogus filename like "RandomBogusFilename.sh" it'll say the job was a success.
Can anyone point out what I'm doing wrong and how I can get Jenkins to actually use my shell script?
The shell script, the job config, and the console output are all shown below. I'm currently trying to do this on a Windows Server 2008 R2 Standard machine.
Thanks.
My .sh file
File Name: surveyToolRequest.sh
File Location: /jobs/Jeff Shell Script Test/workspace
Description:
Hit a web address and retrieve the HTTP Response. Then print out the HTTP Response.
#!/bin/bash
response_code=$(curl -s -o /dev/null -w "%{http_code}" http://SOME-WEBSITE.COM)
echo "The response code is " $response_code
My Jenkins Job Config
Jenkins Console Output
I played with this and found that it worked if I specified the path to the script. If the script is in your job's workspace directory,
./surveyToolRequest.sh
should work as Jenkins looks for files relative to the root of the workspace.
It's more common to just put the contents of the script file directory into the job configuration; that way you can see what the job is doing and you'll avoid problems like this one.
You should use run "Execute windows batch command" and not "Execute Shell"