I have a bamboo plan with Maven task:
verify -B -Dsonar.branch=${bamboo.repository.branch.name}
the problem is that we have a git branch name that contains a '/': "feature/CATALOG", and this is not a valid sonar.branch name.
If I would be running a script task instead of a Maven task, I would replace / by _ as follows:
mvn verify -B -Dsonar.branch=$(echo ${bamboo.repository.branch.name} | tr / _
Is there a way to achieve this with a Maven task?
that is, is it possible to change a variable with a regex or something else?
ps: I am aware that bamboo is a bad choice, and we are eventually moving to jenkins. however we still need to use bamboo for a while.
Related
I have a bamboo plan with a maven task. I need to pass a maven parameter with the name of the branch.
I can use the variable ${bamboo.repository.branch.name} for this.
However, I need to override this value for some branches (see how to apply a regex to a bamboo variable ).
So, in my bamboo plan I define a variable called branchName, with value ${bamboo.repository.branch.name}.
then, my maven task uses ${bamboo.branchName}, and the branches can override the branchName value when necessary.
So, is this possible? can my bamboo plan variable branchName use another variable ${bamboo.repository.branch.name} as default value?
Well, I tried, and the result is unclear.
If my maven task is:
mvn verify -B -Dsonar.branch=${bamboo.branchName}
this does not work. it executes mvn verify -B -Dsonar.branch=${bamboo.repository.branch.name}
However,
If my maven task is:
mvn verify -B -Dsonar.branch=${bamboo.branchName} -Dignore_var=${bamboo.repository.branch.name}
then ${bamboo.branchName} gets substituted as expected,
and it executes mvn verify -B -Dsonar.branch=develop -Dignore_var=develop
Why is that? Is this a bug or a feature?
So, how to achieve this correctly?
that is, I need a bamboo plan variable branchName with a default value of ${bamboo.repository.branch.name},
which can be overridden by branch plans.
ps: I am aware that bamboo is a bad choice, and we are eventually moving to jenkins. however we still need to use bamboo for a while.
I have created a Bamboo build plan that is supposed to generate artifacts. And it does - I see the generated files on the server. Unfortunately, Bamboo does not copy the files to the desired location -> it does not treat them as artifacts that I can download from Bamboo server.
I am working with Bamboo 4.3.3. The documentation tells me to describe the artifacts location relative to the "working directory", so I am trying to copy everything to ${bamboo.build.working.directory}.
I have tried different location / copy pattern settings, but to no avail.
Where should I put them? I have a scripting environment, and there is no Maven or Ant to help me.
I finally understood what was going on with my artifacts and test results that Bamboo did not see:
Test results: there is a known bug that is affecting all versions up to 4.4.5, which manifests itself in scripting environments. Fortunately, it has a workaround: JUnit Parser: Test results are not found
Bamboo uses system property bamboo.fs.timestamp.precision to define FS timestamp resolution. By default it is set to 100 (ms), please set it to higher value in order to make file date check less strict. Bamboo does the check in the following way:
private boolean isFileRecentEnough(final File file)
{
return file.lastModified() >= (taskStartDate.getTime() - SystemProperty.FS_TIMESTAMP_RESOLUTION_MS.getTypedValue());
}
Other items to check
Double check the task configuration and confirm that it is configured it to look for the test results file in the current working directory of the job (Ex.: C:\Users\ssetayeshfar\bamboo-home-445\xml-data\build-dir\PROJECT-PLAN-JOB) and NOT a sub-directory (Ex. C:\Users\ssetayeshfar\bamboo-home-445\xml-data\build-dir\PROJECT-PLAN-JOB/test-results).
In case test report is not produced by the build (it was produced earlier) use a 'touch' command right before the JUnit task.
Artifacts: at the beginning of my work with Bamboo I did not understand that the working directory is defined PER JOB and tried to copy something produced in a previous job as an artifact of the current one.
I have a Hudson job that runs a maven goal. Before this maven goal is executed I have added a step to run before the build starts, it is a shell script that obtains the version number that I want to use in the 'Goals and options' field.
So in my job configuration, under Build Environment I have checked the Configure M2 Extra Build Steps box and added a shell script before the build. The script looks like this:
export RELEASE={command to extract release version}
echo $RELEASE
And then under the Build section I point to my 'root pom'. In the Goals and options I then want to be able to do something like this:
-Dbuild.release.version=${RELEASE} deploy
Where build.release.version is a maven property referenced in the POM. However since the shell doesn't seem to make its variables global it doesn't work. Any ideas?
The only one I have is to install the Envfile plugin and get the shell script to write out the RELEASE property to a file and then get the plugin to read the file, but the order in which everything is run may cause problems and it seems like there must be simpler way...is there?
Thanks in advance.
I recently wanted to do the same, but AFAIK it's not possible to export values from a pre-build shell to the job environment. If there is a Hudson Plugin for this I've missed it.
What did work, however, was a setup similar to what you were suggesting: having the pre-build shell script write the desired value(s) to a property-file in the workspace, and then using the Parametrized Trigger Plugin to trigger another job that actually does the work (in your case, invoke the Maven job). The plugin can be configured to read the parameters it passes from the property file. So the first job has just the shell script and the post-build triggers, and the second one does the actual work, having the correct parameters available as environment variables.
General idea of the shell script:
echo "foo=bar
baz=`somecmd`" > build.properties
And for your Goals and options, something like:
-Dbuild.release.version=${foo} deploy
Granted, this isn't as elegant as one might want but worked really well for us, since our build was broken into several jobs to begin with, and we can actually reuse the other jobs that the first one triggers (that is, invoke them with different parameters).
When you say it doesn't work, do you mean that your RELEASE variable is not passed to the maven command? I believe the problem is that by default, each line of the shell script is executed separately, so environment variables get lost.
If you want the entire shell script to execute as if it was one script file, make the first line:
#!/bin/sh
I think this is described in the Help information alongside the shell script build step (and if I'm wrong, that's a good place to look for the right syntax).
I'm having an issue with a maven build in hudson. This issue would be fairly easy to resolve if I could see the output of maven with the -X flag passed in. However I can't find a way to do this. If I specify "-X" in the "Goals and options" field of the "Build" section in the job configuration my console output looks exactly the same as if I had not passed the "-X" flag at all. Is the debug logging going somewhere else? Or is there some other way I need to pass the "-X" flag?
UPDATE:
The reason this isn't working is because the build is failing during the "Parsing POMs" part of the hudson process, before it actually kicks off the true maven build and passes in any params I specify in the project. So what I really need is a way to get better logging during the "Parsing POMs" part of a maven build in hudson.
That's what it says in the help text.
Specifies the goals to execute, such
as "clean install" or "deploy". This
field can also accept any other
command line options to Maven, such as
"-e" or "-Dmaven.test.skip=true".
I would have put it there as well.
The maven help gives me the following two options:
-X,--debug Produce execution debug output
-e,--errors Produce execution error messages
May be you can try the --debug or the -e swtich
In Jenkins, and I assume this is true for Hudson as well, command line arguments can be passed to Maven in the "goals" setting. I was able to pass the -X parameter by adding it to the beginning of the "goals".
-X package install
Jenkins apparently blindly appends this setting to the end of the mvn command-line.
I have exactly the same problem with Hudson 1.398 (Maven 2.0.10, jdk 1.6.0_07): the build fails during the parsing of the pom files. It works locally and when launched manually from the Hudson workspace.
That build needs an environment variable to be set (for the path of a module), but the environment variable doesn't seem to be propagated from Hudson to Maven. So, like you, I have also tried to get more details from Maven with the -X option, but it also doesn't seem to be propagated.
I want to automate the execution of Maven release:prepare with Perl so that the user doesn't have to answer the prompts for version names etc. Are there a -D arguments that can be supplied so that no prompting is done? I tried the obvious solution which is to feed the prompt answers to mvn via perl code like this:
my $cmd = qq(mvn release:prepare -DautoVersionSubmodules=true-DpreparationGoals="clean install");
open MVN, "| $cmd";
print MVN "\n"; # default
print MVN "$cur_version";
print MVN "\n";
print MVN "$next_version";
print MVN "\n";
close MVN;
but mvn ignores such input and winds up using the defaults (and doesn't prompt either).
So, are there -D args for the release:prepare plugin:goal?
Thanks.
You can use the following maven command to do that...
mvn --batch-mode release:prepare
This will assume defaults for anything that you would normally be prompted for; it would be like running a release and simply hitting enter every time it asked you a question. For instance, if your current development version of your project was 1.2.3-SNAPSHOT, it would release version 1.2.3 and move your development version up to 1.2.4-SNAPSHOT. It is usually best to let Maven work this things out for you anyway since the goal of maven is to use convention over configuration. However, is you need to specify non-default properties, the maven-release-plugin allow command line property override as well as using a 'release.properties' file for overriding these settings.
For the Maven part, see Performing a Non-interactive Release.
If it is a Perl solution you seek, command-line arguments are usually executed through the system command.
Try system $cmd;
As far as I can tell, there's no need to open and close filehandles.
You can specify everything using arguments to the mvn release:prepare command:
mvn release:prepare -DautoVersionSubmodules=true -DreleaseVersion={your release version} -DdevelopmentVersion={next version}-SNAPSHOT -Dtag={your tag}