Skip to content

Commit

Permalink
Merge pull request #11 from jglick/stage-examples-JENKINS-26107
Browse files Browse the repository at this point in the history
[JENKINS-26107] Examples for blocky stage
  • Loading branch information
jglick committed Aug 31, 2016
2 parents 58f9da3 + deb4b62 commit 4969ce0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 58 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Expand Up @@ -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>
Expand Down
51 changes: 25 additions & 26 deletions src/main/js/samples.js
Expand Up @@ -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
"}"
});
Expand Up @@ -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.)
Expand Down
25 changes: 7 additions & 18 deletions src/main/webapp/snippets/workflow.js
Expand Up @@ -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\
Expand All @@ -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\
Expand All @@ -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\
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -91,10 +91,10 @@ public class SnippetizerTest {

@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")
Expand Down

0 comments on commit 4969ce0

Please sign in to comment.