Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-41950] Properly report errors outside stages
And treat errors in post-build the same whether we're running
post-build within the agent block or not.
  • Loading branch information
abayer committed Feb 11, 2017
1 parent aaa0593 commit de9286d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Expand Up @@ -124,10 +124,22 @@ public class ModelInterpreter implements Serializable {
}
}
}
} catch (Exception e) {
// Catch any errors that may have been thrown outside of the stages proper and make sure we set
// firstError accordingly.
if (firstError == null) {
firstError = e
}
} finally {
// If we hit an exception somewhere *before* we got to stages, we still need to do post-build tasks.
if (!postBuildRun) {
executePostBuild(root)
try {
executePostBuild(root)
} catch (Exception e) {
if (firstError == null) {
firstError = e
}
}
}
}
if (firstError != null) {
Expand Down
Expand Up @@ -141,6 +141,19 @@ public void agentAnyInStage() throws Exception {
.go();
}

@Issue("JENKINS-41950")
@Test
public void nonExistentDockerImage() throws Exception {
assumeDocker();
// Bind mounting /var on OS X doesn't work at the moment
onAllowedOS(PossibleOS.LINUX);

expect(Result.FAILURE, "nonExistentDockerImage")
.logContains("ERROR: script returned exit code 1")
.go();
}


@Test
public void fromDockerfile() throws Exception {
assumeDocker();
Expand Down
@@ -0,0 +1,48 @@
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent {
docker {
image "httpdIDontExist:2.4.12"
args "-v /tmp:/tmp -p 80:80"
}
}
stages {
stage("foo") {
steps {
sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
sh 'echo "The answer is 42"'
}
}
}
post {
always {
deleteDir()
}
}
}



0 comments on commit de9286d

Please sign in to comment.