RUN if [ "$AUTH_MS_PROFILE" = "test" ]; then RUN ["mvn", "verify"]; fi
so, the case is am trying to have two images for prod and test since I don't need to run integration test # prod so, am using build-arg to set dev and test profile
I need to have an if loop if the input is test it should test else it shouldn't
I would move all such conditions to a build_internal.sh file
if [ "$AUTH_MS_PROFILE" = "test" ]; then
mvn verify
fi
Copy this file inside and run it inside the Dockerfile. If you want to use your approach then you just need to use
RUN if [ "$AUTH_MS_PROFILE" = "test" ]; then mvn verify ; fi
Related
I have a Bazel executable target (of type fsharp_binary, but I don't think it should matter) that I can run using bazel run.
bazel run //my_app.exe
I would like to use this executable as a test, so that when I call bazel test it gets built and executed, and a non-zero exit code is considered a test failure.
bazel test //...
What I am looking for is something like this:
test_of_executable(
name = "my_test",
executable = "//my_app.exe",
success_codes = [ 0 ],
)
Then:
bazel test //:my_test
How can I achieve this in Bazel?
Just wrap your app as a sh_test. See for example https://github.com/bazelbuild/bazel/issues/1969.
What I use in my codebase is:
BUILD.bazel:
sh_test(
name = "test",
srcs = ["test.sh"],
data = [
"//:some_binary",
],
)
test.sh
some_project/some_subdir/some_binary
See here for an real example.
Im looking to use Playwright to test against a web page.
The system im working on has 4 different environments that we need to deploy against,
for example the test urls may be
www.test1.com
www.test2.com
www.test3.com
www.test4.com
The first question is how do I target the different Environment? In my playwright config I had a baseUrl but I need to override that.
In addition each environment has different login credentials, how can I create and override these as parameters per environment?
Since Playwright v1.13.0, there is a baseURL option available. You can utilise that in this way probably
In your config.js file, you can have this
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
use: {
baseURL: process.env.URL,
},
};
export default config;
Now in the package.json file, you can have the environment variables set in the test commands for various env in the scripts , like this
...
"scripts": {
"start": "node app.js",
"test1": "URL=www.test1.com mocha --reporter spec",
"test2": "URL=www.test2.com mocha --reporter spec",
.
.
},
...
Similarly you can set the environment variables for the login credentials also and then pass them in the script in the same way the URL is passed.
Another approach to this is to use a Bash script. I use something like the following to run tests across environments, to ensure that my Playwright tests will work in all environments they're run in -
#!/bin/bash
echo "Running tests against env 1";
ENV_URL=https://www.env1.com SOMESERVICE_ENV_URL=http://www.env1.com/scholarship npx playwright test $1;
echo "Running tests against env 2"
ENV_URL=https://env2.com SOMESERVICE_ENV_URL=http://env2.com:4008 npx playwright test $1;
echo "Running tests against env 3";
ENV_URL=http://localhost:3000 SOMESERVICE_ENV_URL=http://localhost:4008 npx playwright test $1;
And then run with ./myScript.sh myTest.test.ts
(In a Bash script, the first argument passed in is available via $1.)
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 want to capture the output on the bash shell when running the following command at the bash prompt.
rails runner "MyCloud::Deployment.checkuser"
Basically checkuser() returns a value of either 1 or 0, which I want to capture at the shell that launched the "rails runner" command.
Based on the written value at the shell, I would like to execute some other command. This checkuser() connects to the cloud, accesses the SQL server and returns the value, so I need to load the rails env.
I run this command in hudson "execute shell" window. How do I go about achieving this task?
Does rake help me with this?
Edit:
#to keep things simple:
module MyCloud
class Deployment
def self.checkuser
return 20
end
end
end
I am running the command from ubuntu box:
sreeni#ubuntu:~/work/co/RoR$ res="$(rails runner "MyCloud::Deployment.checkuser")"
sreeni#ubuntu:~/work/co/RoR$ echo $res
sreeni#ubuntu:~/work/co/RoR$
I want to capture the value that is returned from that check_user() to a variable on the bash shell.
Edit: You are confusing return values (objects returned to the same-language caller) with text output. You need to puts 20 to capture it as a string. You cannot capture return values from one language in another language without a foreign function interface or similar mechanism. A rare exception is the interface between *nix shells like Bash and Dash, where you can capture the return value from one in the other because they both implement something similar to a POSIX shell.
To get the exit code, test the command or $?:
rails runner "MyCloud::Deployment.checkuser"
if [ $? -eq 0 ]
then
echo "Success"
else
echo "Failure"
fi
Short form:
if rails runner "MyCloud::Deployment.checkuser"
then
echo "Success"
else
echo "Failure"
fi
To get string output, use a process substitution (and yes, those inner quotes are correct):
result="$(rails runner "MyCloud::Deployment.checkuser")"
if [ "$result" = '0' ]
then
echo "Success"
else
echo "Failure"
fi
Short form:
if [ "$(rails runner "MyCloud::Deployment.checkuser")" = '0' ]
then
echo "Success"
else
echo "Failure"
fi
To capture both output and exit code:
result="$(rails runner "MyCloud::Deployment.checkuser")"
exit_code=$?