Why is my docker command from ant not executed? - ant

I have a simple docker command
$ docker rm 1234
> Error response from daemon: No such container: 1234
Integration this into ant gives:
<target name="demo">
<exec executable="docker">
<arg value="rm 1234" />
</exec>
</target>
> ant -v demo
> demo:
[exec] Current OS is Linux
[exec] Executing 'docker' with arguments:
[exec] 'rm 1234'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] docker: 'rm 1234' is not a docker command. See 'docker --help'.
[exec] Result: 1
Can someone explain to me (a) where this different behavior comes from and (b) how to fix it (getting docker run from ant-target)?

You are passing a single argument through, your ant is the equivalent of saying
$ docker 'rm 1234'
Try
<target name="demo">
<exec executable="docker">
<arg value="rm" />
<arg value="1234" />
</exec>
</target>

Related

How to write this docker shell script in powershell, in building an image in Jenkins?

Here is a shell script used in Jenkins. The $version should be replaced with the set parameter in Jenkins.
docker build -t gitlab.x.com:3030/directory:$version -f windows-config/backend/Dockerfile .
I want to run it on powershell but the logs says "invalid argument "gitlab.x.com:3030/directory:" for "-t, --tag" flag: invalid reference format."
It probably is a syntax problem with the $version
I tried changing it to
docker build -t 'gitlab.x.com:3030/directory:$version' -f windows-config/backend/Dockerfile .
but the logs say ""docker build" requires exactly 1 argument. See 'docker build --help'."

Why docker image build throws /usr/bin/env: ‘sh\r’: No such file or directory?

Building docker image.......
/usr/bin/env: ‘sh\r’: No such file or directory
execution failed
complete script
#!/bin/bash
echo "Building docker image......."
. gradle.properties
IMAGE="$dockerRegistry/$1"
IMAGE_TAG="$releaseVersion-$(git log -1 --pretty=%h)"
if ./gradlew clean :$1:jibDockerBuild -x test; then
echo "Pushing docker image...."
docker tag $IMAGE $IMAGE:$IMAGE_TAG
docker push $IMAGE:$IMAGE_TAG
else
echo "execution failed"
exit 1
fi
exit 0
Try to adjust your file endings for gradlew file:
dos2unix .\gradlew

Why the environment variables shown by shell and jenkins different?

I found the environment variables shown by shell and jenkins is different. When I see $PATH by echo, it shows as follows;
# cat /etc/passwd | grep jenkins
jenkins:x:998:997:Jenkins Continuous Integration Server:/var/lib/jenkins:/bin/bash
# su jenkins
bash-4.2$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
However when I exec "echo $PATH" on Jenkins by (Build -> Execute shell), console log shows as follows;
[workspace] $ /bin/sh -xe /tmp/hudson6923847933544830986.sh
+ echo /sbin:/usr/sbin:/bin:/usr/bin
/sbin:/usr/sbin:/bin:/usr/bin
Finished: SUCCESS
Not only $PATH but many other variables are also different, but $PATH is important to execute command and I don't understand why they are not the same. Do you have any idea?
Maybe your user of shell and user who is building the job are not same.
run $ whoami command in your shell and jenkins (Build -> Execute shell).
You can also set PATH variable in Build -> Execute shell section or jenkins -> Manage Jenkins -> configure System -> Global properties section. check the Environment variables then Name: PATH, value: $PATH:/usr/local/sbin.

Is there a way to run a script file using a command from inside the neo4j shell?

I would like to run a script file by using a command in the shell or power console of neo4j.
Is there a way?
Clarification: it is really the goal of running a script from within the shell.
Something like the gsh command for running a groovy script.
Take a look at Mark Needham's World Cup Dataset GitHub example where he has used the Neo4j shell to run a series of Cypher scripts for data import.
https://github.com/mneedham/neo4j-worldcup/blob/master/doit.sh
#! /bin/bash
set -e
if [[ -z "$WC_DB" ]]; then
echo "Make sure you set \$WC_DB before running this script"
echo "e.g. export WC_DB=\"/path/to/neo4j-community-2.1.4\""
exit 1
fi
echo "starting up Neo4j instance at ${WC_DB}"
${WC_DB}/bin/neo4j status
if [ $? -ne 0 ]; then
echo "Neo4j not started. Run ${WC_DB}/bin/neo4j start before running this script"
fi
${WC_DB}/bin/neo4j-shell --file data/import/clear.cyp
${WC_DB}/bin/neo4j-shell --file data/import/indexes.cyp
${WC_DB}/bin/neo4j-shell --file data/import/loadMatches.cyp
${WC_DB}/bin/neo4j-shell --file data/import/loadSquads.cyp
${WC_DB}/bin/neo4j-shell --file data/import/loadLineUps.cyp
${WC_DB}/bin/neo4j-shell --file data/import/loadEvents.cyp
${WC_DB}/bin/neo4j-shell --file data/import/connectAdjacentWorldCups.cyp
${WC_DB}/bin/neo4j-shell --file data/import/addGeoLocations.cyp
${WC_DB}/bin/neo4j-shell --file data/import/loadCountryInformation.cyp
${WC_DB}/bin/neo4j-shell --file data/import/addContinents.cyp
Making sure that you have exported the system variable $WC_DB to contain the path to your running Neo4j instance. You can see that the flag --file allows you to pass in a Cypher script as a file to the neo4j-shell as an argument.

Variables in bash script in sshexec from ant

I have a problem with variables in sshexec task.
My build.xml ant script looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project name="sshexecproject" basedir="." default="build">
<target name="build">
<sshexec
host="192.168.2.106"
username="root"
password="xxx"
commandResource="${basedir}/to_run.sh"
trust="true"
verbose="true"
failonerror="true"
/>
</target>
In the to_run script I have two variables:
#!/bin/bash
name="Pink Panther"
export name2="Panther Pink"
echo "Name: "
echo $name
echo "Name with export: "
echo $name2
If I run the script on terminal i get the following output:
$ ./to_run.sh
Name:
Pink Panther
Name with export:
Panther Pink
We can see that all works fine. But if I start the build.xml script from ant i get the following output:
...
[sshexec] Authentication succeeded (password).
[sshexec] cmd : #!/bin/bash
[sshexec] cmd :
[sshexec] cmd : name="Pink Panther"
[sshexec] cmd : export name2="Panther Pink"
[sshexec] cmd :
[sshexec] cmd : echo "Name: "
[sshexec] Name:
[sshexec] cmd : echo $name
[sshexec]
[sshexec] cmd : echo "Name with export: "
[sshexec] Name with export:
[sshexec] cmd : echo $name2
[sshexec]
[sshexec] Disconnecting from ...
We can see that on the remote server this script create an empty echo. The variable name and name2 is not filled. Why?
Changing this line:
commandResource="${basedir}/to_run.sh"
to
command="${basedir}/to_run.sh"
results in the following:
[sshexec] Authentication succeeded (password).
[sshexec] cmd : /data/tmp/anttest/to_run.sh
[sshexec] Name:
[sshexec] Pink Panther
[sshexec] Name with export:
[sshexec] Panther Pink
commandResource takes a resource file with a list of commands and executes each line individually with bash -c $LINE so any variables defined are only valid on the same line. command executes the whole script in the same shell.

Resources