Run `bash` command on Jenkins in windows hang forever - jenkins

I am running Jenkins job on a windows10 machine. And I have installed ubuntu shell on the windows. The Jenkins job works fine with windows batch commands. But it stuck there when I try to run bash command. For example, I created an Execute Windows batch command build step, if I put command bash -c ls, this command never finishes.
It works fine if I run the same command in the windows directly.
How can I configure Jenkins job to work with bash command?
Below is the build step configuration. There are two commands. The first one is used to install dependencies on my nodejs application. The second command is used to run a command in bash shell. The problem is that the build is stuck on the second command.

Have you made any Global configurations in jenkins. try giving the command with the home path of Ubuntu shell and re run the command once.

Related

how to run docker build command in jenkins shell prompt

I want to run docker build command in Jenkins shell prompt.
Have already installed docker and add Jenkins user in docker usergroup.
But when i hit docker build command it shows me permission denied issue and when i am using sudo prefix it ask for password with -S argument.
I am running all commands on Jenkins master, earlier i used on other node server not master.
So what is best way to resolve this.

How create a freestyle jenkins job which is running in docker

I have a simple c++ to compile and run using jenkins freestyle job it is working fine if I use jenkins built in my OS (Linux mint tricia) commands I use:
cd "destination"
g++ main.cpp -o test
./test
everything is working good.
BUT,now I m running jenkins from docker container and when I try to do this I get error cant cd to "destination", I know this is because docker is isolated from host machine, So I want to ask how could I make a simple freestyle job which executes programs which is on my host machine using jenkins which is running inside docker?
Thank You
Just run your jenknis container with volume like docker run -it -v destination:destination jenkins

Run a script inside docker container using octopus deploy

Trying to do config transformation once a docker container has been created and the docker CP command does not allow wildcard and file type searches. While testing manually, it was found that it was possible to solve this issue but running the docker exec command and running powershell inside our container. After some preliminary tests it doesn't look like this works out of the box with octopus deploy. Is there a way to run process steps inside a container with octopus deploy?
Turns out you can run powershell scripts that already exist in the container with the exec command:
docker exec <container> powershell script.ps1 -argument foo
This command will run a script as you would expect in command line.

How does the Jenkins CloudBees Docker Build Plugin set its Shell Path

I'm working with a Jenkins install I've inherited. This install has the CloudBees Docker Custom Build Environment Plugin installed. We think this plugin gives us a nifty Build inside a Docker container checkbox in our build configuration. When we configure jobs with this option, it looks like (based on Jenkins console output) Jenkins runs the build with the following command
Docker container 548ab230991a452af639deed5eccb304026105804b38194d98250583bd7bb83q started to host the build
[WIP-Tests] $ docker exec -t 548ab230991a452af639deed5eccb304026105804b38194d98250583bd7bb83q /bin/sh -xe /tmp/hudson7939624860798651072.sh
However -- we've found that this runs /bin/sh with a very limited set of environmental variables -- including a $PATH that doesn't include /bin! So
How does the CloudBees Docker Custom Build Environment Plugin setup its /bin/sh environment. Is this user configurable via the UI (if so, where?)
It looks like Jenkins is using docker exec -- which i think means that it must have (invisibly) setup a container with a long running process using docker run. Doesn't anyone know how the CloudBees Docker Custom Build Environment Plugin plugin invokes docker run, and if this is user manageable?
Considering this plugin is "up for adoption", I would recommend the official JENKINS/Docker Pipeline Plugin.
It source code show very few recent commits.
But don't forget any container has a default entrypoint set to /bin/sh
ENTRYPOINT ["/bin/sh", "-c"]
Then:
The docker container is ran after SCM has been checked-out into a slave workspace, then all later build commands are executed within the container thanks to docker exec introduced in Docker 1.3
That means the image you will be pulling or building/running must have a shell, to allow the docker exec to execute a command in it.

Jenkins SSH shell closes before executing remote commands

I have a Jenkins job with the following commands under "Execute shell":
ssh jenkins#172.31.12.58
pwd
I want the Jenkins server to connect via SSH to the remote server then run a command on the remote server.
Instead, Jenkins connects to the remote server, disconnects immediately, then runs the pwd command locally as can be seen in the output:
Started by user Johanan Lieberman
Building in workspace /var/lib/jenkins/jobs/Test Github build/workspace
[workspace] $ /bin/sh -xe /tmp/hudson266272646442487328.sh
+ ssh jenkins#172.31.12.58
Pseudo-terminal will not be allocated because stdin is not a terminal.
+ pwd
/var/lib/jenkins/jobs/Test Github build/workspace
Finished: SUCCESS
Edit: Any idea why the subsequent commands after the ssh command aren't run inside the SSH shell, but rather run locally instead?
If you're not running interactively, SSH does not create an interactive session (thus the "Pseudo-terminal" error message you see), so it's not quite the same as executing a sequence of commands in an interactive terminal.
To run a specific command through an SSH session, use:
ssh jenkins#YOUR_IP 'uname -a'
The remote command must be quoted properly as a single argument to the ssh command. Or use the bash here-doc syntax for a simple multi-line script:
ssh jenkins#YOUR_IP <<EOF
pwd
uname -a
EOF
I think you can use the Publish Over SSH plugin to execute commands on a slave with SSH:
If the Source files field is mandatory, maybe you can transfer a dummy file.
Update:
Another solution is to use the SSH plugin. Maybe it's a better solution compare to the other plugin :)

Resources