Unable to access directory inside workspace in jenkins - maven

So I have a Jenkins job wherein as part of the build.
I run one script which creates a folder in the workspace say "test"
so the script runs fine and creates the folder test.
After this, I have a maven command wherein I want to access this test folder(as an argument) I am trying it as $workspace/test
but it's not working.
Can anyone guide if i am missing anything here

Can you give us more information - maybe code snippets?
I'm not sure what you mean with 'maven command' and '$workspace/test'
If you want use a variable in a pom.xml like:
<path>${workspace}</path>
you will have to assign it in the properties:
<workspace>...location...</workspace>
Otherwise you can use maven preassigned variables like
${basedir}/

Related

Pass a file as a property while calling a maven goal in Jenkins v2.263.1

I am migrating all my jobs from Jenkins v1.651.3 to Jenkins v2.263.1.
Currently I am passing a file stored in my Linux server as a property under Invoke top-level maven targets build step in Jenkins.
e.g. property.a=/home/user1/props/a.properties and property.b=/home/user1/props/b.properties
In Jenkins v2.263.1, I am running all my jobs in a docker container which is created dynamically.
Where and how can I store this file so that I can pass this as a property to maven build like -Dproperty.a=/home/user1/props/a.properties and -Dproperty.b=/home/user1/props/b.properties
I tried adding these files in Managed Files section under Manage Jenkins option and passing these as -Dproperty.a=a.properties to maven build through Jenkinsfile, however, it did not work. Not sure if it's the right way.
Please let me now if there's a way to handle this.
Thanks in advance!

Where does Jenkins store the project source

I have a Jenkins job that uses a script to build my project. On the following line, the script fails mvn -e -X -Dgit='$git' release:prepare.
Because I want to search for the cause of this, I want to go to the Jenkins server and run mvn -e -X -Dgit='$git' release:prepare from the command line, to see if it works.
Does Jenkins store the projects' source code somewhere, such that I can go to that folder and call Maven?
If yes, then where?
Yes, It Stores the project files for the job by default at
/var/lib/jenkins/workspace/{your-job-name}
This is where jenkins suppose the project files to be present or it pulls it from a source before start working/building from it.
Quote from Andrew M.:
"Hudson/Jenkins doesn't quite work that way. It stores configurations and job information in /var/lib/jenkins by default (if you're using the .deb package). If you want to setup persistence for a specific application, that's something you'll want to handle yourself - Hudson is a continuous integration server, not a test framework.
Check out the Wiki article on Continuous Integration for an overview of what to expect."
From this Question on serverfault.
This worked for me:
/var/jenkins/workspace/JobNameExample
but, if your build machine (node) is a different than the one where Jenkins is running (manager), You need specify it:
/var/jenkins/workspace/JobNameExample/label/NodeName
Where you can define label too:
jenkins stores its workspace files currently in /var/jenkins_home/workspace/project_name
I am running from docker though!

How can I run single groovy class file independently in gradle?

I have 2 groovy class files under one rootProject. I want to run just one of them without running the other one. How can I do that using intellij command line and command prompt. Right now when I run the rootProject both files run one after the other. Is there any setting required build.gradle file then please explain hoow can I do that as I am very new to gradle and don't know much about it. Thanks!
If you have only those two groovy scripts (and there is nothing to compile etc.), you do not need Gradle to run it at all. From command line call
groovy <filename>.groovy
To run the script directly from Gradle Script, use
new GroovyShell().run(file('somePath'))
Yes you can create intellij config to run your script.
Follow these steps:
1) Edit configuration
2) Add new Groovy configuration
3) Browse you script
4) Run your script

Executing gradle scripts from external directories

I need to execute groovy script with gradle, but the thing is that these scripts are located in external directory (let's say it's Desktop). I've heard, that in previous versions of Gradle (currently working on 3.2.1) it was not possible, since it is not part of the gradle project. I wonder if it is possible now, or do I have to copy all these scripts into some folder located in gradle project, to execute it.
User story:
I found script in external directory (based on some properties passed to console) - I have absolute path to the script
Now I want to execute this script (build.gradle) without copying it into my gradle project
I'm pretty green with gradle and I hope I made my point clear.
Thanks for help and every attempt :)
Is that what you're looking for? To run the script clone the repository, navigate to 42556631/project folder and run the command:
gradle -b ../script/build.gradle clean build
yes you need to move build.gradle file into project/Build Script folder and then run it.

Not able to run command for maven in jenkins

I have a maven project which I want to build on Jenkins. I am giving goal as
clean install -Desb_env=dev
I have mention esb_env in mule-app.properties file. Same command is working fine & picking up the value of esb_env in local machine.But same command is not working on jenkins. It gives error as
Property ESB_ENV could not be found
Like this there few more goal need to give, I could not proceed further. Don't know what is wrong with Jenkins.
I have checked path for repo as well.
Any help would be appreciated.
This is the way we are specifying parameter in mule-app.properties file. keeping it blank & providing value through command.
ESB_ENV=
secure.properties=key
key=

Resources