Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #11 from jglick/stage-examples-JENKINS-26107
[JENKINS-26107] Examples for blocky stage
- Loading branch information
|
@@ -151,12 +151,6 @@ |
|
|
<version>2.0</version> |
|
|
<scope>test</scope> |
|
|
</dependency> |
|
|
<dependency> |
|
|
<groupId>org.jenkins-ci.plugins</groupId> |
|
|
<artifactId>pipeline-stage-step</artifactId> |
|
|
<version>2.0</version> |
|
|
<scope>test</scope> |
|
|
</dependency> |
|
|
<dependency> |
|
|
<groupId>org.jenkins-ci.plugins</groupId> |
|
|
<artifactId>matrix-auth</artifactId> |
|
|
|
@@ -45,38 +45,37 @@ function getSample(sampleName) { |
|
|
samples.push({ |
|
|
name: 'hello', |
|
|
title: 'Hello World', |
|
|
script: "node {\n" + |
|
|
" stage 'Stage 1'\n" + |
|
|
" echo 'Hello World 1'\n" + |
|
|
" stage 'Stage 2'\n" + |
|
|
" echo 'Hello World 2'\n" + |
|
|
script: |
|
|
"node {\n" + |
|
|
" echo 'Hello World'\n" + |
|
|
"}" |
|
|
}); |
|
|
|
|
|
samples.push({ |
|
|
name: 'github-maven', |
|
|
title: 'GitHub + Maven', |
|
|
script: "node {\n" + |
|
|
" // Mark the code checkout 'stage'....\n" + |
|
|
" stage 'Checkout'\n" + |
|
|
"\n" + |
|
|
" // Get some code from a GitHub repository\n" + |
|
|
" git 'https://github.com/jglick/simple-maven-project-with-tests.git'\n" + |
|
|
"\n" + |
|
|
" // Get the maven tool.\n" + |
|
|
" // ** NOTE: This 'M3' maven tool must be configured\n" + |
|
|
" // ** in the global configuration. \n" + |
|
|
" def mvnHome = tool 'M3'\n" + |
|
|
"\n" + |
|
|
" // Mark the code build 'stage'....\n" + |
|
|
" stage 'Build'\n" + |
|
|
" // Run the maven build\n" + |
|
|
" if (isUnix()) {\n" + |
|
|
" sh \"'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package\"\n" + |
|
|
" } else {\n" + |
|
|
" bat(/\"${mvnHome}\\bin\\mvn\" -Dmaven.test.failure.ignore clean package/)\n" + |
|
|
script: |
|
|
"node {\n" + |
|
|
" def mvnHome\n" + |
|
|
" stage('Preparation') { // for display purposes\n" + |
|
|
" // Get some code from a GitHub repository\n" + |
|
|
" git 'https://github.com/jglick/simple-maven-project-with-tests.git'\n" + |
|
|
" // Get the Maven tool.\n" + |
|
|
" // ** NOTE: This 'M3' Maven tool must be configured\n" + |
|
|
" // ** in the global configuration. \n" + |
|
|
" mvnHome = tool 'M3'\n" + |
|
|
" }\n" + |
|
|
" stage('Build') {\n" + |
|
|
" // Run the maven build\n" + |
|
|
" if (isUnix()) {\n" + |
|
|
" sh \"'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package\"\n" + |
|
|
" } else {\n" + |
|
|
" bat(/\"${mvnHome}\\bin\\mvn\" -Dmaven.test.failure.ignore clean package/)\n" + |
|
|
" }\n" + |
|
|
" }\n" + |
|
|
" stage('Results') {\n" + |
|
|
" junit '**/target/surefire-reports/TEST-*.xml'\n" + // assumes junit & workflow-basic-steps up to date |
|
|
" archive 'target/*.jar'\n" + // TODO Jenkins 2 use archiveArtifacts instead |
|
|
" }\n" + |
|
|
" junit '**/target/surefire-reports/TEST-*.xml'\n" + // assumes junit & workflow-basic-steps up to date |
|
|
" archive 'target/*.jar'\n" + // TODO Jenkins 2 use archiveArtifacts instead |
|
|
"}" |
|
|
}); |
|
@@ -44,15 +44,15 @@ THE SOFTWARE. |
|
|
<p> |
|
|
Step parameters are given as key-value pairs; if there is just one mandatory parameter the name may be omitted, so |
|
|
</p> |
|
|
<pre>stage 'Build'</pre> |
|
|
<pre>readFile 'build.properties'</pre> |
|
|
<p> |
|
|
is a shortcut for |
|
|
</p> |
|
|
<pre>stage name: 'Build'</pre> |
|
|
<pre>readFile file: 'build.properties'</pre> |
|
|
<p> |
|
|
but if you specify multiple parameters they must all be named: |
|
|
</p> |
|
|
<pre>stage name: 'Build', concurrency: 1</pre> |
|
|
<pre>readFile file: 'build.properties', encoding: 'ISO-8859-1'</pre> |
|
|
<p> |
|
|
Many steps require complex nested configuration for a parameter. |
|
|
(And some nested configuration objects in turn have object-typed parameters.) |
|
|
|
@@ -62,35 +62,24 @@ snippet for++\n\ |
|
|
for (int ${1:i} = 0; $1 < ${2:Things}.length; $1++) {\n\ |
|
|
${3:$2[$1]}$0\n\ |
|
|
}\n\ |
|
|
# stage\n\ |
|
|
snippet stage\n\ |
|
|
stage '${1}'\n\ |
|
|
# node\n\ |
|
|
snippet node\n\ |
|
|
node {\n\ |
|
|
${1}\n\ |
|
|
}\n\ |
|
|
# node-l ('label') \n\ |
|
|
snippet node-l\n\ |
|
|
node ('${1}') {\n\ |
|
|
\n\ |
|
|
}\n\ |
|
|
"; |
|
|
|
|
|
// TODO: Would be nice to get this from the backend via an AJAX call. |
|
|
// With each step contributing 1 or more snippets of code |
|
|
var workflowSnippets = |
|
|
"# stage\n\ |
|
|
snippet stage\n\ |
|
|
stage '${1}'\n\ |
|
|
stage('${1}')\n\ |
|
|
${2}\n\ |
|
|
}\n\ |
|
|
# node\n\ |
|
|
snippet node\n\ |
|
|
node {\n\ |
|
|
${1}\n\ |
|
|
}\n\ |
|
|
# node-l ('label') \n\ |
|
|
snippet node-l\n\ |
|
|
node ('${1}') {\n\ |
|
|
node('${1}') {\n\ |
|
|
\n\ |
|
|
}\n\ |
|
|
# echo \n\ |
|
@@ -113,7 +102,7 @@ snippet fileExists (in workspace)\n\ |
|
|
fileExists('${1}')\n\ |
|
|
# dir (subDir) \n\ |
|
|
snippet dir (subDir)\n\ |
|
|
dir ('${1}') {\n\ |
|
|
dir('${1}') {\n\ |
|
|
${2}\n\ |
|
|
}\n\ |
|
|
# pwd \n\ |
|
@@ -124,12 +113,12 @@ snippet deleteDir\n\ |
|
|
deleteDir()\n\ |
|
|
# deleteDir (subDir) \n\ |
|
|
snippet deleteDir (subDir)\n\ |
|
|
dir ('${1}') {\n\ |
|
|
dir('${1}') {\n\ |
|
|
deleteDir()\n\ |
|
|
}\n\ |
|
|
# retry (count) \n\ |
|
|
snippet retry (count)\n\ |
|
|
retry (${1:2}) {\n\ |
|
|
retry(${1:2}) {\n\ |
|
|
\n\ |
|
|
}\n\ |
|
|
# sleep \n\ |
|
|
|
@@ -39,8 +39,8 @@ |
|
|
import org.jenkinsci.plugins.workflow.steps.CoreStep; |
|
|
import org.jenkinsci.plugins.workflow.steps.EchoStep; |
|
|
import org.jenkinsci.plugins.workflow.steps.PwdStep; |
|
|
import org.jenkinsci.plugins.workflow.steps.ReadFileStep; |
|
|
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStep; |
|
|
import org.jenkinsci.plugins.workflow.support.steps.StageStep; |
|
|
import org.jenkinsci.plugins.workflow.support.steps.WorkspaceStep; |
|
|
import org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep; |
|
|
import org.jenkinsci.plugins.workflow.support.steps.input.InputStep; |
|
@@ -91,10 +91,10 @@ |
|
|
|
|
|
@Test public void basics() throws Exception { |
|
|
st.assertRoundTrip(new EchoStep("hello world"), "echo 'hello world'"); |
|
|
StageStep s = new StageStep("Build"); |
|
|
st.assertRoundTrip(s, "stage 'Build'"); |
|
|
s.concurrency = 1; |
|
|
st.assertRoundTrip(s, "stage concurrency: 1, name: 'Build'"); |
|
|
ReadFileStep s = new ReadFileStep("build.properties"); |
|
|
st.assertRoundTrip(s, "readFile 'build.properties'"); |
|
|
s.setEncoding("ISO-8859-1"); |
|
|
st.assertRoundTrip(s, "readFile encoding: 'ISO-8859-1', file: 'build.properties'"); |
|
|
} |
|
|
|
|
|
@Email("https://groups.google.com/forum/#!topicsearchin/jenkinsci-users/workflow/jenkinsci-users/DJ15tkEQPw0") |
|
|