Jenkins shell fetching secret txt - bash

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

Related

How to set application credential details in CI?

How to set application credential details in buildkite so that it can be used as part of tests?
Any help?
thanks in Advance
The easiest way is to store them in an agent environment hook, which is a script file you need to put on the host running the agent, and is invoked just before every job the agent runs:
# /etc/buildkite-agent/hooks/environment
set -eu
echo "--- :house_with_garden: Setting up the environment"
export APPLICATION_PASSWORD="xxx"
and then use them in your pipeline commands from the environment:
# .buildkite/pipeline.yml
steps:
- label: Run tests
command: ./run-tests --password="$$APPLICATION_PASSWORD"
The double-dollar escapes the variable for pipeline upload, making sure that the password is not interpolated into the YAML and then submitted to buildkite.com. It will then be interpolated once the agent runs the command.
You could also access $APPLICATION_PASSWORD within your script to avoid mentioning it in the yaml at all.
The agent environment hook works best if you're running long lived agents, or use something like the elastic-ci-stack-for-aws which has a shared environment hook for this sort of thing:
https://github.com/buildkite/elastic-ci-stack-for-aws#build-secrets
but there are a few other options, too:
https://buildkite.com/docs/pipelines/secrets

Reading Export commands from Linux script stdin

I have written a script where I need to input creds with the export command.
I am using read command to get those values in the script.
This is what I need to input when the script asks for input. I want to give entire input at one shot.
export AWS_ACCESS_KEY_ID="XXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXX"
export AWS_SESSION_TOKEN="XXXXXXX"
The portion of the script:
read inputawscreds
$aws cloudformation get-stack-policy --stack-name=$cloudformation_stack --region=$region | $jq '.StackPolicyBody' > $policy_backup_filename
This script takes the exported creds and then use creds to run aws cli.
This script runs in a loop where i need to give set of inputs creds (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) at each times

Groovy Execute Bash Script in Jenkins

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.

Jenkins - Passing variable password to external shell

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

Jenkins - Execute Shell Build Step Not Working

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"

Resources