Currently, I have a Jenkins multibranch pipeline. It clones my git repo and builds the solution via a Jenkinsfile. The Jenkinsfile has 5 stages:
checkout scm
restore nugets (using nuget.exe)
Build Debug config of solution using msbuild from command line:
--> bat "\"${tool 'VS2017'}\"\MsBuild.exe %WORKSPACE%\mysolution.sln /p:Configuration=Debug /p:Platform=\"x64\""
Build Release config of solution using msbuild from command line (same cmd line as above)
Build Custom config of solution using msbuild from command line (same cmd line as above)
So right now this does three builds back to back using MSBuild. Intermittently, one of the the builds fail. The error I get:
(MarkupCompilePass1 target) ->
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9): error MC1000: Unknown build error, 'Object reference not set to an instance of an object.'
Not sure why this happens. But as mentioned it only happens sometimes. Other times the build passes successfully. I have a feeling this has to do with an update as this never hapened before. Either with the MSBuild (VS 2017) or a Windows Update (Server 2016).
Any help on this greatly appreciated
Related
I am trying to do code coverage for node js project via Jenkins, I’ve one doubt that where to add the “sonar-project.properties” file, it in root repository that means in sonar-scanner installed repository or in the jenkins path i.e. “/var/lib/jenkins/workspace/$JOB_NAME/”,
can some help to fix this I’m getting error while executing the pipeline.
Error log as follows:
/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/sonardemo/bin/sonar-scanner
/var/lib/jenkins/workspace/demosonar#tmp/durable-f32cf5e2/script.sh: 1: /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/sonardemo/bin/sonar-scanner: not found
[Pipeline] }
WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succeed?
I have a batch Job (not the pipeline Job) in Jenkins where I am using a plugin called "Naginator" which will check if the current build is failed/unstable - If the current build is failed/unstable it will run immediately the next build to confirm the error is genuine. If the error is not genuine then the run is successful and it will periodically set the next build to run. Along with this, I use some CMD commands to move my data into another folder with the Build number as my folder name.
Now here is the issue, if the previous build was unstable and Naginator runs the next build and that build is stable then what I need to do is delete the previous unstable build data from the folder manually. Is it possible to fetch the previous build number in Jenkins so that I can delete the file in an automated way - lets say in CMD Commands .BAT file.
Jenkins has it's own global variables. You can check whem in your pipeline job -> Pipeline Syntax -> Global Variables Reference.
Additionally check http://jenkins_url:port/env-vars.html/
For your purpose BUILD_NUMBER exist.
Just create new env var like this:
PREV_BUILD_NUMBER = $($BUILD_NUMBER -1)
Excuse me if this piece of code will not work, I'm not good about scripting) Just for example.
UPDATE:
also you can find in mentioned reference a list of variables:
previousBuild
previousBuildInProgress
previousBuiltBuild
previousCompletedBuild
previousFailedBuild
previousNotFailedBuild
previousSuccessfulBuild
I have Jenkins V2.7 with a freestyle project running on Windows 7,
One of the build steps is “Execute Windows batch command”, in this step I run some .exe which do some stuff and also set environment variable TEST to Z:\DATA
Recently I have updated Jenkins and plugins to V2.144 and now when I run the job the TEST variable is set to Z:DATA instead of Z:\DATA
Any idea what can cause this issue ?
I configured a Jenkins project B to run when project A completes succesfully.
How can I find the buildnumber of A in the project B pipeline?
If you just need the last successful build of A you can just read it from Jenkins:
http://JenkinsMaster:Port/job/MyJob/lastSuccessfulBuild/buildNumber
If you need the build the triggered B you can use the Parametized Trigger Plugin and use :
TRIGGERED_BUILD_NUMBER_MyJob="Last build number triggered"
You can do the following:
Use the Execute windows batch or Execute shell build step to store the build version in a file during the build of project A - e.g. from a windows batch:
echo "VARIABLEA=%BUILD_NUMBER%" > %WORKSPACE%\myartifact.properties:
Use the Archive the artifacts post build step to store the file against that build in project A
At the start of project B use the Copy artifacts from another project build step, point to project A and use the Artifacts to copy field to filter down to the file you created and choos Last successful build for the Which build field
Read the file in a shell script during the build of project A to pickup the build number
If you output the artifact in the format:
VARIABLEA=${BUILD_NUMBER}
VARIABLEB=${BUILD_NUMBER}
and you're using Linux on the Jenkins server, you could use the source command to make VARIABLEA and VARIABLEB available in that shell session, e.g.:
source "${WORKSPACE}/myartifact.properties"
echo ${VARIABLEA}
You could then do something with that variable in the shell script.
Alternately, you could simply use the Trigger parameterized build on other projects post build step (which I believe requires the Parameterized Trigger Plugin) on project A and setup project B to accept those parameters.
I'm trying to set up an sbt build on a CloudBees-hosted Jenkins server. The repository is stored in GitHub, and Jenkins is pulling the repository fine as I can see all the code in the workspace.
However, when I try to run the build I get the following output:
...
Seen branch in repository origin/master
Seen 2 remote branches
Commencing build of Revision 763eecd49a522a50e53c6f24e40e5f2e984d3737 (origin/HEAD, origin/master)
Checking out Revision 763eecd49a522a50e53c6f24e40e5f2e984d3737 (origin/HEAD, origin/master)
Warning : There are multiple branch changesets here
[ProjectName] $ java -Dsbt.log.noformat=true -jar /opt/sbt/sbt-launch-0.7.4.jar clean test
Name: No value provided for Name
Build step 'Build using sbt' changed build result to FAILURE
Build step 'Build using sbt' marked build as failure
Finished: FAILURE
The build runs fine on two other machines, even when run using an equivalent command line to the one Jenkins is using. The project itself is a multi-project build with Play Framework.
THis is probably due to having the incorrect version of the sbt-launch jar in your global config's sbt section. If you update it to say /opt/sbt/sbt-launch-0.13.0.jar that should resolve your problem