gitlab ci : get variable in pom.xml and use in script - gitlab

I use gitlab for my java project. I'm on windows.
How to retrieve the version value in the pom.xml and use it in my script please?
buildProd:
stage: build
tags:
- prod
script:
- asadmin stop-domain domain1
- mvn -Pprod -DskipTests=true clean install
- rm -r -fo "C:/Program Files/glassfish6/glassfish/domains/domain1/applications/*"
- rm -r -fo "C:/Program Files/glassfish6/glassfish/domains/domain1/generated/*"
- rm -r -fo "C:/Program Files/glassfish6/glassfish/domains/domain1/session-store/*"
- VERSION=$(mvn help:evaluate -Dexpression=version -q -DforceStdout)
- echo $VERSION
- cp -fo "versions/$VERSION/engine "C:\engine-api"
- Start-Service -Name "domain1"
only:
- master
Thank you.
UPDATE 2023-01-26 21:51
[INFO]
------------------------------------------------------------------------ $ rm -r -fo "C:/Program
Files/glassfish6/glassfish/domains/domain1/applications/" $ rm -r
-fo "C:/Program Files/glassfish6/glassfish/domains/domain1/generated/" $ rm -r -fo
"C:/Program
Files/glassfish6/glassfish/domains/domain1/session-store/*" $ cp -fo
"target/welcom.war" "C:/Program
Files/glassfish6/glassfish/domains/domain1/autodeploy" $
VERSION=$(mvn help:evaluate -Dexpression=version -q -DforceStdout)
VERSION=$(mvn help:evaluate -Dexpression=version -q -DforceStdout) :
Le terme «VERSION=$(mvn help:evaluate -Dexpression=version -q
-DforceStdout)» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou programme exécutable. Vérifiez
l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le
chemin d'accès est correct et réessayez. Au caractère Ligne:1 : 1
VERSION=$(mvn help:evaluate -Dexpression=version -q -DforceStdout) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (VERSION=$(mvn h... -DforceStdout):String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
System.Management.Automation.PSCustomObjectSystem.Object1Pr�paration des modules � la
premi�re utilisation.0-1-1Completed-1
ERROR: Job failed: exit status 1

Related

unable to pass values from bash to curl with pipe

I am developing a script in bash. This script receives a parameter by pipe and passes it to the script.
The problem is that the script is receiving null values.
# curl -s -d 'PATH_ROOT="/opt"' http://dominio.com/setup_cmi/install_cmi.sh |bash
$PATH_ROOT esta vacia, debe indicar el directorio raiz
#!/bin/bash
#Dependencias
declare -a dependencias=( "unzip" "wget" "curl" "mkdir" "tree" )
#command -V unzip
echo "Content-Type: text/plain"
echo
PATH_ROOT=$1
if [ -z "$PATH_ROOT" ]; then
echo "\$PATH_ROOT esta vacia, debe indicar el directorio raiz"
exit;
else
for i in "${dependencias[#]}"; do
command -V $i
if [ $? = 1 ]; then
exit;
fi
done
fi
Also try making the call in this way, with the same result:
curl -s http://dominio.com/setup_cmi/install_cmi.sh | bash -s -- /opt

script bash Linux don't find error

I have to verify in a script bash that a folder exists. The problem is, it does but the script tells me that my file does not exist.
I don't find the error and I have searched on the internet and I do exactly the way it says to do( on Openclassroom, forum, ...).
here is my script:
#!/bin/bash
if [ $# -ne 1 ] && [ -d $1 ]; then
echo "Usage : $0 dir">/dev/stderr
exit 1
fi
backup="~/backup"
echo $backup , argument = $1
if [ ! -e ${backup} ]; then
echo "Le dossier backup n'existe pas">/dev/stderr
exit 1
fi
if [ ! -d $backup ]; then
echo "le document backup n'est pas un fichier">/dev/stderr
exit 1
fi
if [ -w $backup ]; then
echo "Le dossier backup n'est pas protégé en écriture">/dev/stderr
exit 1
fi
il qu$if [! chmod u=+w $backup ]; then
echo "une erreur c'est produite">/dev/stderr
exit 1
fi
And what it said in the shell + the proof that the file backup exist in the correct repertory:
guy#PC-DE-GUY:~/bash/Chap9$ ./backup.sh ~/seance06/
~/backup , argument = /home/guy/seance06/
Le dossier backup n'existe pas
guy#PC-DE-GUY:~/bash/Chap9$ ~/backup
bash: /home/guy/backup : est un dossier
guy#PC-DE-GUY:~/bash/Chap9$ cd ~/backup
guy#PC-DE-GUY:~/backup$
The issue is with the ~ character inside quotes, in backup="~/backup" (line 6). BASH processes it as a character, not as an alias to your home directory, so your code runs the checks on the string '~/backup', instead of '/home/guy/backup'.
To use ~ as an alias to your home directory, it should be outside quotes: backup=~/backup
If you want to hardcode your home directory, I suggest you use $HOME instead of ~. It's clearer to understand.
You can test what I tried to explain with the following code:
#!/bin/bash
# Save this file as test.sh
# run this script with ~ as an argument:
# ./test.sh ~
echo "Value for \$HOME: $HOME"
echo "Value for ~ inside quotes: ~"
echo "Value for ~ outside quotes:" ~
echo "Value for \$1: $1"
If you save the code above as test.sh and you run it as: ./test.sh ~, outputs will be:
Value for $HOME: /home/guy
Value for ~ inside quotes: ~
Value for ~ outside quotes: /home/guy
Value for $1: /home/guy

RPM spec patch application fails

I have a spec file, which compiles fine without the patch:
build#SLES11SP4-185:~/rpmbuild/SPECS> cat testSoftware.spec
#
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#
# norootforbuild
Name: testSoftware
Version: 1.0
Release: 2
Summary: Demo - patch
Group: Deployment
License: GPLv2
Url: www.dell.com
#PreReq:
#Provides:
#BuildRequires:
Source: testSoftware.tar.gz
patch0: test1.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
AutoReqProv: on
%description
Authors:
--------
Raj Kumar
%prep
%setup -q
%build
%install
mkdir -p $RPM_BUILD_ROOT/opt/testSoftware
install test1.sh $RPM_BUILD_ROOT/opt/testSoftware
install test2.sh $RPM_BUILD_ROOT/opt/testSoftware
%patch -P 0
%clean
rm -rf $RPM_BUILD_ROOT
%post
%postun
%files
/opt/testSoftware/test1.sh
/opt/testSoftware/test2.sh
%defattr(-,root,root,0755)
My SOURCES directory has the test1.patch and the *.tar.gz
build#SLES11SP4-185:~/rpmbuild/SOURCES> ls
testSoftware.tar.gz
test1.patch testSoftware-1.0
Here is the test1.patch
build#SLES11SP4-185:~/rpmbuild/SOURCES> cat test1.patch
--- testSoftware-1.0/test1.sh 2016-08-20 04:49:19.000000000 -0400
+++ test1.sh 2016-08-20 05:33:45.000000000 -0400
## -1 +1 ##
-Hello - Test1
+Test1 - Test1 - patch
When i run the spec file, it fails:
build#SLES11SP4-185:~/rpmbuild/SPECS> rpmbuild -bb testSoftware.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.10960
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd /home/build/rpmbuild/BUILD
+ rm -rf testSoftware-1.0
+ /usr/bin/gzip -dc /home/build/rpmbuild/SOURCES/testSoftware.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd testSoftware-1.0
++ /usr/bin/id -u
+ '[' 1001 = 0 ']'
++ /usr/bin/id -u
+ '[' 1001 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.10960
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ /bin/rm -rf /var/tmp/testSoftware-1.0-build
++ dirname /var/tmp/testSoftware-1.0-build
+ /bin/mkdir -p /var/tmp
+ /bin/mkdir /var/tmp/testSoftware-1.0-build
+ cd testSoftware-1.0
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.10960
+ umask 022
+ cd /home/build/rpmbuild/BUILD
+ cd testSoftware-1.0
+ mkdir -p /var/tmp/testSoftware-1.0-build/opt/testSoftware
+ install test1.sh /var/tmp/testSoftware-1.0-build/opt/testSoftware
+ install test2.sh /var/tmp/testSoftware-1.0-build/opt/testSoftware
+ %patch -P 0
/var/tmp/rpm-tmp.10960: line 28: fg: no job control
error: Bad exit status from /var/tmp/rpm-tmp.10960 (%install)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.10960 (%install)
Can someone tell me what is the issue?
You can see it is not recognizing the %patch macro and sending that text exactly to the shell, which interprets the % as trying to refer to a background job-control process. That is because %patch is a %build step and is in the wrong section of the specfile (you have it in %install).
Move it to %build and you should be fine.
It works if we apply it after %setup -q.
Below is the modified spec file which works:
Name: testSoftware
Version: 1.0
Release: 2
Summary: Demo - patch
Group: Deployment
License: GPLv2
Url: www.dell.com
#PreReq:
#Provides:
#BuildRequires:
Source: testSoftware.tar.gz
Patch0: test1.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
AutoReqProv: on
%description
Authors:
--------
Raj Kumar
%prep
%setup -q
%patch -p0
%build
%install
mkdir -p $RPM_BUILD_ROOT/opt/testSoftware
install test1.sh $RPM_BUILD_ROOT/opt/testSoftware
install test2.sh $RPM_BUILD_ROOT/opt/testSoftware
%clean
rm -rf $RPM_BUILD_ROOT

BASH Linux : syntax error « ;; »

i have a syntax error « ;; »
Syntax error near unexpected token « ;; »
my code
#!/bin/bash
# Bash Menu
clear
echo "Decryptor"
PS3='entrez votre chois: '
options=("update" "decryptor" "Quit")
select opt in "${options[#]}"
do
case $opt in
"update")
php updatekey.php
break
;;
"decryptor")
#Nom de la video
read -p "Nom de la série : " name
#detection du fichier .png
find . -name "*.png" | while read line
oname="$(basename "${line}" .png)"
#décryption du fichier png
php -e AES.class.php "${oname}".png
#on change le nom du fichier
mv "${oname}".ass "${name}".ass
read -p "voulez vous télécharger la video (Y/N)? "
[ "$(echo $REPLY | tr [:upper:] [:lower:])" == "y" ] || exit
read -p "entrez liens :" src
read -p "liens vod" vod
rtmpdump -v -T '567ghgh' -r "$vod" -a "vod" -f "WIN 13,0,0,182" -W "http://yoyo.com/components/yoyo.swf" -p "http://yoyo.com" -y "mp4:$src" -o "$name.mp4"
break
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
is part of code with error
why I get an error I modified the script a bit and this part to not move and I now have an error
What can be the cause
thank you :)
Line 21 contains the beginning of an incomplete while statement. The parser only notices because ;; is illegal when it's still looking for the do.
find stuff | while read line
echo you can have multiple commands here --
echo the exit code of the expression is
echo examined by '"while"'
do
echo ... Body of while loop
done
Your code lacks the do and done parts, and it's unclear to Bash (and to us) where they should go.

cp command don't create directory in a sh\bash script, why?

I am very new in sh/bash script and I have the following problem:
I have a script that create some directory and copy into it some files but seems not work !!!
In my script I have the following lines of code:
# Creazione Nuovo Pacchetto per Ubuntu
JRE_I386="jre1.6.0_35-i386"
JRE_AMD64="jre1.6.0_35-x86_64"
ApplicationName="XCloud"
# Se il primo parametro è una stringa vuota mostra il messaggio di errore ed esce:
if [ -z $1 ]; then
echo "Usage: createpkg.sh <rev package>"
exit
# Altrimenti setta la variabile CURRENT_VERSION con il valore del parametro di input passato:
else
CURRENT_VERSION=$1
fi
echo ---------------------------------------------------------------------------------------------------
echo ---------------------------------------------------------------------------------------------------
echo
echo CREAZIONE NUOVO PACCHETTO ${ApplicationName}${CURRENT_VERSION}
echo
echo ---------------------------------------------------------------------------------------------------
echo ---------------------------------------------------------------------------------------------------
# Verifica esistenza ambiente prima di generare la nuova versione. Se esiste torna ERRORE:
if [ -e "${ApplicationName}${CURRENT_VERSION}ubuntu1-i386" ]; then
echo "Errore: la cartella contenente la nuova versione da creare gia' esiste"
exit
fi
if [ -e "${ApplicationName}${CURRENT_VERSION}ubuntu1-amd64" ]; then
echo "Errore: la cartella contenente la nuova versione da creare gia' esiste"
exit
fi
# Copia dell' alberatura completa (recursive and force), copia PACKAGE nella destinazione:
cp -Rf PACKAGE ${ApplicationName}${CURRENT_VERSION}ubuntu1-i386
cp -Rf PACKAGE ${ApplicationName}${CURRENT_VERSION}ubuntu1-amd64
echo "Copia dell' alberatura completata"
# Copia della JRE corretta:
cp -Rf ../JRE/${JRE_I386} ${ApplicationName}${CURRENT_VERSION}ubuntu1-i386/usr/share/${ApplicationName}/jre1.6.0_35
cp -Rf ../JRE/${JRE_AMD64} ${ApplicationName}${CURRENT_VERSION}ubuntu1-amd64/usr/share/${ApplicationName}/jre1.6.0_35
echo "Copia della JRE corretta completata"
......................................................................................
......................................................................................
SOME OTHER STUFF
......................................................................................
......................................................................................
The problem occurs with the last 2 cp command because when it try to execute these lines:
cp -Rf ../JRE/${JRE_I386} ${ApplicationName}${CURRENT_VERSION}ubuntu1-i386/usr/share/${ApplicationName}/jre1.6.0_35
cp -Rf ../JRE/${JRE_AMD64} ${ApplicationName}${CURRENT_VERSION}ubuntu1-amd64/usr/share/${ApplicationName}/jre1.6.0_35
when I go to execute the script, in the shell, it say to me something that in english sound like: impossible to create directory "DIRECTORYNAME": File or directory does not exist
Infact my output in the shell is the following one:
cp: impossibile creare la directory "XCloud1ubuntu1-i386/usr/share/XCloud/jre1.6.0_35": File o directory non esistente
cp: impossibile creare la directory "XCloud1ubuntu1-amd64/usr/share/XCloud/jre1.6.0_35": File o directory non esistente
What is the problem? What am I doing wrong?
Tnx
Andrea
You need to create directories before copying into them , look at command mkdir
Try adding
mkdir -p ${ApplicationName}${CURRENT_VERSION}ubuntu1-i386/usr/share/${ApplicationName}/jre1.6.0_35
and
mkdir -p ${ApplicationName}${CURRENT_VERSION}ubuntu1-amd64/usr/share/${ApplicationName}/jre1.6.0_35
just before the two cp lines.
Look at here, how to copy files and create directory if it does not exist:
Linux: copy and create destination dir if it does not exist
You can check if the directort is exist like this:
if [ -d ~/directorypath ]; then
echo "exist!"
else
mkdir ~/directorypath
fi
you can do it in one code line:
if [ ! -d ~/directorypath ]; then mkdir ~/directorypath; fi
First create directory for given path
mkdir /home/test
then copy file from destination to source
cp /home.a.txt /home/test

Resources