0

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
jeyGey
  • 161
  • 3
  • 15
  • By default, Maven project version property is `project.version`, not `version`. Is that what you want ? – amanin Jan 26 '23 at 20:44
  • no, project.version doesn't work. In command line this is what I want: mvn help:evaluate -Dexpression=version -q -DforceStdout the only problem is that I can't use it in gitlab-ci – jeyGey Jan 26 '23 at 20:47
  • Can you add the error message in your question ? It could help to understand what is wrong with the CI. – amanin Jan 26 '23 at 20:50
  • As your CI seems to run on windows, you should use batch or powershell command instead of shell. I don't know windows very well, so I cannot provide an answer. Maybe this other post can help you: https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file – amanin Jan 26 '23 at 20:58
  • it doesn't help me but thanks anyway – jeyGey Jan 26 '23 at 21:47
  • ok I found it was necessary to put $VERSION= – jeyGey Jan 26 '23 at 22:22

0 Answers0