I have a batch file in which I set the ant path and junit path values hard coded and it executes my build.xml and everything works fine.
When I replace the hard coded value of the path with something like
set Path=%CURRENT DIRECTORY%\bin
it is not working.
How to make this work.
Here is my batch file
set CURRENT_DIRECTORY=%~dp0
set ANT_HOME=c:\ant\apache-ant-1.8.3
ECHO current directory is %CURRENT_DIRECTORY%
ECHO %ANT_HOME%
set Path=%ANT_HOME%\bin
set ADAPTER_LIBRAY_PATH=%1
set USER_JAR_PATH=%2
set CLASS_NAME=%3
set RESULTS_PATH=%4
set JUNIT_PATH=C:\ANT\test\junit-4.1.jar
set LIBRAIES_TO_INCLUDE="%JUNIT_PATH%";"%ADAPTER_LIBRAY_PATH%";"%USER_JAR_PATH%"
ECHO %LIBRAIES_TO_INCLUDE%
ECHO %ADAPTER_LIBRAY_PATH%
ECHO %JUNIT_PATH%
ECHO %USER_JAR_PATH%
ECHO %CLASS_NAME%
ECHO %RESULTS_PATH%
ant -lib "%LIBRAIES_TO_INCLUDE%" -Dlibraries="%ADAPTER_LIBRAY_PATH%" -Djunitlibrary="%JUNIT_PATH%" -Djartobeexec="%USER_JAR_PATH%" -Duserclass=%CLASS_NAME% -Dresultspath=%RESULTS_PATH% -buildfile build.xml test-html
Try this:
SET ANT_HOME = ant_directory
"%JAVA_HOME%\bin\java" -Xmx512M -XX:MaxPermSize=256M -cp %ANT_HOME%/lib/ant-launcher.jar -Dant.home="%ANT_HOME%" -Dant.library.dir="%ANT_HOME%/lib" org.apache.tools.ant.launch.Launcher -f build.xml %*
Related
I have a legacy project in Jenkins that hast to be pipelined (for
later parallelization), hence moving from simple tcsh script to
pipeline
running the script as
#!/bin/tcsh
source ./mysetting.sh
update
works but the same pipeline step fails due to missing alias expansion
stage ('update') {
steps {
//should be working but alias expansion fails
sh 'tcsh -c "source ./mysettings.sh; alias; update"'
//manually expanding the alias works fine
sh 'tcsh -c "source ./mysettings.sh; alias; python update.py;"'
}
}
calling alias in the steps properly lists all the set aliases, so I
can see them, but not use them.
I know in bash alias expansion has to be set
#enable shell option for alias_expansion
shopt -s expand_aliases
but in csh/tcsh that should be taken care of by source.
what am I missing?
found the solution:
sh '#!/bin/tcsh \n' +
'source ./mysettings.sh \n' +
'echo "Calling my alias" \n' +
'my_alias \n'
every line starting with sh launches a new shell, so it has to be in one line including line breaks.
further adding to the confusing was that documentation of jenkins says that it starts "a bash" but it launched /bin/sh which in my case pointed to something else
We have this workspace and subdirectory:
$WORKSPACE/Refrens data/11. metadata/file.xml
in Jenkins section Execute Shell we have this code:
DEPLOY_FILE=$WORKSPACE/Refrens data/11. metadata/file.xml
if [[ -s $DEPLOY_FILE ]];
then
echo "$WORKSPACE/$DEPLOY_FILE exits in Bitbucket"
echo ""
else
echo "$WORKSPACE/$DEPLOY_FILE does not exits in Bitbucket"
exit 1;
fi
When building it says that this file does not exist and the else part is executed
$WORKSPACE/Referens data/11. metadata/file.xml does not exist in Bitbucket
But our file exist!
I think Jenkins does not understand space in the directory names Reference data and 11. metadata how do I fix it?
I'm trying to set up a Jenkins pipeline which will run a liquibase update whenever something is pushed to the master branch. The liquibase runner plugin for Jenkins has a security risk and therefore, I can't install it and run liquibase updates from that.
My liquibase* file (the bash script) is in my repository at the following path
/repo/liquibase/liquibase/liquibase*
I've set up the pipeline to run the following shell script. NOTE: I have the command set to liquibase --help for test purposes, but normally I'd want to run an update command.
export PATH=$PATH:/var/lib/jenkins/workspace/repo/liquibase
export PATH=$PATH:/var/lib/jenkins/workspace/repo/liquibase/liquibase
export PATH=$PATH:/var/lib/jenkins/workspace/repo/liquibase/liquibase/liquibase
export PATH=$PATH:/var/lib/jenkins/workspace/repo/liquibase/liquibase/jre/bin
cd liquibase
ls -ltr
chmod 755 liquibase/liquibase
chmod 755 liquibase/jre/bin/java.exe
liquibase --help
The liquibase --help command runs fine from the directory path /repo/liquibase in git bash. However, when I run it from Jenkins, I get the following error.
/var/lib/jenkins/workspace/Database_and_Repos/liquibase/liquibase/liquibase/jre/bin/java: No such file or directory
Build step 'Execute shell' marked build as failure
My liquibase file looks like this and it is the last line in the file that is causing the error.
#!/usr/bin/env bash
if [ ! -n "${LIQUIBASE_HOME+x}" ]; then
# echo "LIQUIBASE_HOME is not set."
## resolve links - $0 may be a symlink
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
LIQUIBASE_HOME=`dirname "$PRG"`
# make it fully qualified
LIQUIBASE_HOME=`cd "$LIQUIBASE_HOME" && pwd`
# echo "Liquibase Home: $LIQUIBASE_HOME"
fi
# build classpath from all jars in lib
if [ -f /usr/bin/cygpath ]; then
CP=.
for i in "$LIQUIBASE_HOME"/liquibase*.jar; do
i=`cygpath --windows "$i"`
CP="$CP;$i"
done
for i in "$LIQUIBASE_HOME"/lib/*.jar; do
i=`cygpath --windows "$i"`
CP="$CP;$i"
done
else
if [[ $(uname) = MINGW* ]]; then
CP_SEPARATOR=";"
else
CP_SEPARATOR=":"
fi
CP=.
for i in "$LIQUIBASE_HOME"/liquibase*.jar; do
CP="$CP""$CP_SEPARATOR""$i"
done
CP="$CP""$CP_SEPARATOR""$LIQUIBASE_HOME/lib/"
for i in "$LIQUIBASE_HOME"/lib/*.jar; do
CP="$CP""$CP_SEPARATOR""$i"
done
fi
if [ -z "${JAVA_HOME}" ]; then
#JAVA_HOME not set, try to find a bundled version
if [ -d "${LIQUIBASE_HOME}/jre" ]; then
JAVA_HOME="$LIQUIBASE_HOME/jre"
elif [ -d "${LIQUIBASE_HOME}/.install4j/jre.bundle/Contents/Home" ]; then
JAVA_HOME="${LIQUIBASE_HOME}/.install4j/jre.bundle/Contents/Home"
fi
fi
if [ -z "${JAVA_HOME}" ]; then
JAVA_PATH="$(which java)"
if [ -z "${JAVA_PATH}" ]; then
echo "Cannot find java in your path. Install java or use the JAVA_HOME environment variable"
fi
else
#Use path in JAVA_HOME
JAVA_PATH="${JAVA_HOME}/bin/java"
fi
# add any JVM options here
JAVA_OPTS="${JAVA_OPTS-}"
"${JAVA_PATH}" -cp "$CP" $JAVA_OPTS liquibase.integration.commandline.Main ${1+"$#"}
Has anyone run into this problem with liquibase commands in Jenkins? I've been googling all day, but haven't found much similar to this exact issue. Any help in the right direction would be great.
(We're updating the Liquibase Runner plugin. We have a release that is being reviewed for the security issues by the Jenkins team now.)
The error message seems to say that your "Execute shell" command in your changelog is not working correctly. Maybe the command is not installed, maybe it's calling a script that is not on your build machine.
One way to explore this to add an "echo" of the "Execute shell" command prior. Also, I'd pass --logLeve=DEBUG to Liquibase to get a better idea on the command it's trying to run.
Thanks for using Liquibase and Jenkins! I'll be talking about it here next month: https://www.cloudbees.com/devops-world/.
You could use the liquibase-maven-plugin and just call the maven phase in the pipeline:
sh mvn resources:resources liquibase:update
As for me, it is the best decision. Follow the official documentation
I have a config file that has some environment variable including a variable called MONGO_UUID and I pass this variable to a test step via a configFileProvider plugin and save it to .env file as in step below:
stage('Build ') {
steps {
configFileProvider([configFile(fileId: 'jenkins_config_filename', variable: "CONFIG_FILE")]) {
sh '''
cp -f $CONFIG_FILE ./.env
npm run test // this step dynamically updates MONGO_UUID
echo "$MONGO_UUID" // trying to output newly updated value here
'''
jenkins_config_filename has following format:
MONGO_HOST=123.123.123.1
MONGO_DB=dbname
MONGO_US=user
MONGO_UUID=null
What I am trying to do is to output variable MONGO_UUID which was passed to the test step via config file and the value of MONGO_UUID get updated in the process. I can see that the MONGO_UUID got updated because I can see new record in mongodb but I am wondering how to echo that value in jenkins console.
add this line (with proper changes based on your MongoDB configuration) after npm run test:
MONGO_UUID=`mongo db.collection.find("whatever you query is")`
and then you can echo the variable to Jenkins output.
If you want to update the file, you can use sed like below :
sed -i "s/MONGO_UUID=.*/MONGO_UUID=${MONGO_UUID}/" .env
I have a jenkins JOb which is calling the BAT file which contains the call for As java -jar testrunscripts/SQLWorkbench/sqlworkbench.jar -url=jdbc:as400:/;"translate binary"=true;naming=sql;libraries=; -driver=com.ibm.as400.access.AS400JDBCDriver -username=-password=-driverjar=E:\\\\resources\\lib\\jt400.jar -script='testrunscripts/HISTORYANDNEWDIFF.sql'
1-Jenkins Integrats the SQLWorkbench which calls the one sqlscript(HISTORYANDNEWDIFF.sql). which needs the dynamic table name required .
WbExport -file='E:\\TestingDATABASE\\history_XAXPGRFE.csv' -type=text -delimiter=',';
select * from %SOURCE%.XAXPGRFE where XPORIG='JAVAPGM'
How would pass the parameter to the query from the jenkins pipeline to bat file and then sql script
Your question is a bit unclear but try to call the bat script from your Jenkins job with a key value pair:
your_bat_script.bat param1=value1
and then in the bat script call the SQL Workbench /J script (HISTORYANDNEWDIFF.sql) using the -variable flag:
java -jar testrunscripts/SQLWorkbench/sqlworkbench.jar -url=jdbc:as400:/;"translate binary"=true;naming=sql;libraries=; -driver=com.ibm.as400.access.AS400JDBCDriver -username=-password=-driverjar=E:\\resources\lib\jt400.jar -script='testrunscripts/HISTORYANDNEWDIFF.sql -variable %1'
http://www.sql-workbench.net/manual/commandline.html#cmdline-vardef
%1 will contain param1=value1