|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2015 CloudBees, Inc. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package org.jenkinsci.plugins.workflow; |
| 26 | + |
| 27 | +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; |
| 28 | +import org.jenkinsci.plugins.workflow.job.WorkflowJob; |
| 29 | +import org.junit.Rule; |
| 30 | +import org.junit.Test; |
| 31 | +import org.jvnet.hudson.test.JenkinsRule; |
| 32 | + |
| 33 | +/** |
| 34 | + * Verifies that specific environment variables are available. |
| 35 | + * |
| 36 | + */ |
| 37 | +public class EnvWorkflowTest { |
| 38 | + |
| 39 | + @Rule public JenkinsRule r = new JenkinsRule(); |
| 40 | + |
| 41 | + /** |
| 42 | + * Verifies if NODE_NAME environment variable is available on a slave node and on master. |
| 43 | + * |
| 44 | + * @throws Exception |
| 45 | + */ |
| 46 | + @Test public void areAvailable() throws Exception { |
| 47 | + r.createSlave("node-test", null, null); |
| 48 | + WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "workflow-test"); |
| 49 | + |
| 50 | + p.setDefinition(new CpsFlowDefinition( |
| 51 | + "node('master') {\n" + |
| 52 | + " echo \"My name on master is ${env.NODE_NAME}\"\n" + |
| 53 | + "}\n" |
| 54 | + )); |
| 55 | + r.assertLogContains("My name on master is master", r.assertBuildStatusSuccess(p.scheduleBuild2(0))); |
| 56 | + |
| 57 | + p.setDefinition(new CpsFlowDefinition( |
| 58 | + "node('node-test') {\n" + |
| 59 | + " echo \"My name on a slave is ${env.NODE_NAME}\"\n" + |
| 60 | + "}\n" |
| 61 | + )); |
| 62 | + r.assertLogContains("My name on a slave is node-test", r.assertBuildStatusSuccess(p.scheduleBuild2(0))); |
| 63 | + } |
| 64 | +} |
0 commit comments