Credential Binding does not work in Windows batch command Jenkins - batch-file

I'm kind of stuck with the Jenkins credential binding.
I'm using the Bindings tab and created a secret text and the variable for the same is pwd
and I use the variable in the "Execute Windows batch command" step and I'm running the below command on a windows node.
echo password is $pwd
and the output is always literal
password is $pwd
Even printing of existing environment variables like $BUILD_NUMBER does not work.
Why isn't my secret text binding not working? Shouldn't the variable be expanded in my build step? Can anyone please point me to what is the mistake that I'm making here.
Thanks in advance!!

The var just needs to be printed as %var%.

I was using secret text to store password of sql server login and just using %var% didn't work for me
If you are using the var for password, Use it as "%var%"

Related

How to use an AWS RDS token as a password in postres uri connection string?

I am using a tool that connects to a postgres database usinga URI string to connect. Normally this has worked fine for me by just doing postgres://<username>:<password>#<host>:<port>/<database>. However, I have moved my database to AWS RDS and now for the database password I am now using an auth token. The token looks like:
rdspostgres.cdgmuqiadpid.us-west-2.rds.amazonaws.com:5432/?Action=connect&DBUser=jane_doe&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=900...
When I put this in for the password it is not able to parse correctly because of the token format. For example i get the error psql: invalid URI query parameter: "Action". How do I use tokens as passwords for a string? Is there a way I need to encode it?
Also worth noting that for sanity check I tried connecting with psql -d $DATABASE -p $PORT -U $USER --no-password, having set $PGPASSWORD as an environment variable. This worked great and I was able to connect, so it has to be something with parsing the password string.
I run into the same issue and was able to solve it using urlencoded-byte-serializer. I'm using Rust, so the code looks the following:
fn urlencode(token: &str) -> String {
url::form_urlencoded::byte_serialize(token.as_bytes()).collect()
}
Here is how the token looks after the encoding:
my-proxy.proxy-qzf4e5cf6ve.us-east-1.rds.amazonaws.com%3A5432%2F%3FAction%3Dconnect%26DBUser%3Dusers%26X-Amz-Algorithm%3DAWS4-HMAC-SHA256...
Have you checked that the parameters you pass through the URI, have to go through an options section of your tool?
Maybe, your problem is not password. I think, your problem is the tool can't understand yours params. Because the error begins when begins yours params.
Check, your syntax.
I am for example using DataGrip, and in this tool you need split each part of your URI and put in the correct label, like a form.

Start a session in MobaXterm from batch script

When I had Windows 7, the following batch command opened MobaXterm, and inside, it opened a new tab (in addition to the home tab) that connected to a VM ('linux-server'):
start "" "C:\Program Files (x86)\MobaXterm\MobaXterm.exe" -newtab linux-server
Now, in Windows 10, the command does not work well. It opens MobaXterm, but does not open a session to the VM.
I tried to run the command from command-line, the result is the same.
My requests are:
Opening a session to the VM in MobaXterm using batch command (the "home tab" that was opened in the past is unnecessary)
I use private key to connect this session, for some reason, Moba does not save the passphrase for the private key, only the user's password. I would like to save the passphrase as well.
Thanks in advance!
From the MobaTek Blog
MobaXterm.exe -newtab ["<Command>"]:
This command can be used to start a new tab inside a running instance of MobaXterm (or start a new instance of MobaXterm if no other instance is running) and immediately execute a given MobaXterm command
So you would need to specify a ssh command to connect to your virtual machine.
You could also save the ssh connection (or any other connection type) as a "first level" bookmark and use the bookmark-command instead:
MobaXterm.exe -bookmark "<Bookmark_name>":
This command can be used to start a bookmark by specifying its name.
In your case, the command would look like this, if your bookmark would be called "linux-server"
start "" "C:\Program Files (x86)\MobaXterm\MobaXterm.exe" -bookmark linux-server
I'm providing example usage for opening mobaxterm with specific command. Below is an example of opening a MobaXterm portable Personal edition in a newtab mode with SSH and a specified username.
MobaXterm_Personal_20.6.exe -newtab "ssh -l username 192.168.1.99"

Pre populating host, username, and password for WinSCP login using .cmd file

I have created a .cmd file that allows the user to select a number that corresponds to a different set of login credentials for WinSCP thus eliminating the need to memorize login credentials for WinSCP.
In my .cmd file I have set host, username, and password according to the following:
SET UID=exampleusername
SET PWD=examplepassword
SET HOST=examplehost
I then proceed to call WinSCP using
start WinSCP.exe
This opens the login interface:
The WinSCP interface is called correctly but I am having issues coding in my .cmd file to populate the Host Name, User name, and Password fields using the variables defined in my .cmd file.
You cannot populate the WinSCP login dialog from a command-line.
All you can do is to have WinSCP open the session directly by calling it like:
start WinSCP.exe sftp://%UID%:%PWD%#%HOST%/
References:
Opening a session from a command-line
Session URL syntax
Anyway, I do not see why you implement batch-file menu for opening sessions on WinSCP. Did you consider pre-configuring stored sites for WinSCP instead?
Btw, you are using some really ancient version of WinSCP (5 years old at least). You need to upgrade urgently.

bulkupload without username/password prompt

I have a process which generates daily some data, which I would like to update to a java app running on the appengine using bulkupload, using the command:
appcfg.py upload_data
--url=http://your_app_id.appspot.com/_ah/remote_api --kind= --filename=
It works perfectly, but it always asks me for my username/password.
Is there any way to save the credentials, use certificates, to avoid the username prompt?
Add these options:
--email=
--passin
and at the end : < "your password file.txt"
Seems this technique no longer works with SDK 1.9.17. The updated docs include some new oauth2 command line options, but the instructions are rather confusing. Anyone able to use either the old passin or the new oauth2 techniques? How?

login to remote using "mstsc /admin" with password

I want to use mstsc /admin to login to a server silently. My batch file reads the code as
mstsc /v:xxx.xxx.xxx.xxx /admin
But it ask me to enter password. Can anyone help me to skip this step?
I went on to Google and found this site. But I am very new to this stuff (scripting) and could not understand what to do with given code. Is it a vbscript file? Can I do the same thing with a batch file. Please elaborate and I request you to spoon feed. This is not my arena but still I am pushed to fight without weapons.
My basic need is to kick off all users from a remote desktop except mine to perform some maintainable work. Thanks.
Re-posted as an answer:
Found an alternative (Tested in Win8):
cmdkey /generic:"<server>" /user:"<user>" /pass:"<pass>"
Run that and if you run:
mstsc /v:<server>
You should not get an authentication prompt.
the command posted by Milad and Sandy did not work for me with mstsc. i had to add TERMSRV to the /generic switch. i found this information here: https://gist.github.com/jdforsythe/48a022ee22c8ec912b7e
cmdkey /generic:TERMSRV/<server> /user:<username> /pass:<password>
i could then use mstsc /v:<server> without getting prompted for the login.
to be secured, you should execute 3 commands :
cmdkey /generic:"server-address" /user:"username" /pass:"password"
mstsc /v:server-address
cmdkey /delete:server-address
first command to save the credential
second command to open remote desktop
and the third command to delete the credential for security reason
all of these commands can be saved in a batch file(bat).
(if you save these command in a batch file, third command will not be executed until you close the remote desk)
Same problem but #Angelo answer didn't work for me, because I'm using same server with different credentials. I used the approach below and tested it on Windows 10.
cmdkey /add:server01 /user:<username> /pass:<password>
Then used mstsc /v:server01 to connect to the server.
The point is to use names instead of ip addresses to avoid conflict between credentials. If you don't have a DNS server locally accessible try c:\windows\system32\drivers\etc\hosts file.
It became a popular question and I got a notification. I am sorry, I forgot to answer before which I should have done. I solved it long back.
net use \\10.100.110.120\C$ MyPassword /user:domain\username /persistent:Yes
Run it in a batch file and you should get what you are looking for.
Save your username, password and sever name in an RDP file and run the RDP file from your script
The Command mentioned above didn't work for me (Windows 11)
cmdkey /generic:"server-address" /user:"username" /pass:"password"
When i listed the cmdkeys using the commad:
cmdkey /list
I saw, that a legacy target was added. Adding a specific TERMSRV-Target worked for me:
cmdkey /add:Domain:target=TERMSRV/<SERVER> /user:<DOMAIN>\<USER> /pass:<PASSWORD>

Resources