-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial native
checkout scm
support (#380)
* Preliminary attempt at native `checkout scm` support Signed-off-by: Andrew Bayer <[email protected]> * Add test for `checkout scm` support Signed-off-by: Andrew Bayer <[email protected]> * Move to using a vanilla-package smoke test for `checkout scm` Signed-off-by: Andrew Bayer <[email protected]> * Switch from XML for creds/scm config to YAML Signed-off-by: Andrew Bayer <[email protected]> * Add credentials to test Signed-off-by: Andrew Bayer <[email protected]> * Switch to optional credentials in SCM YAML rather than standalone. Signed-off-by: Andrew Bayer <[email protected]> * Adding docs for `checkout scm` support. Signed-off-by: Andrew Bayer <[email protected]> * Fix exception handling, add link to SCM.adoc from README, document lack of Pipeline as YAML support Signed-off-by: Andrew Bayer <[email protected]>
- Loading branch information
Showing
11 changed files
with
310 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
= Using `checkout scm` with Jenkinsfile Runner | ||
:toc: | ||
:toc-placement: preamble | ||
:toclevels: 3 | ||
|
||
By default, Jenkinsfile Runner will use the directory containing the Jenkinsfile as | ||
the workspace for builds. However, this will not work correctly with external agents | ||
or plugins that expect to interact with the SCM. In order to enable these behaviors, | ||
you can specify a YAML file containing the definition of the SCM to checkout in the build. | ||
|
||
== Specifying an SCM definition on the CLI | ||
|
||
Add the `--scm (path to YAML file)` option to your `jenkinsfile-runner` invocation. | ||
Nothing else needs to be changed. Note that Pipeline as YAML is not currently supported | ||
with the `--scm` option. | ||
|
||
== SCM YAML format | ||
|
||
The SCM YAML format matches with Jenkins Configuration-as-Code syntax. For example: | ||
|
||
[source,yaml] | ||
---- | ||
scm: | ||
git: | ||
userRemoteConfigs: | ||
- url: https://github.com/jenkinsci/jenkinsfile-runner.git | ||
branches: | ||
- name: master | ||
---- | ||
|
||
== Specifying and using credentials with `checkout scm` | ||
|
||
You can specify credentials to be used when checking out the configured SCM by | ||
adding the credentials definition to your YAML and referencing the ID in the SCM's | ||
configuration. For example: | ||
|
||
[source,yaml] | ||
---- | ||
credential: | ||
usernamePassword: | ||
password: secret | ||
scope: GLOBAL | ||
id: user1 | ||
username: user1 | ||
scm: | ||
git: | ||
userRemoteConfigs: | ||
- url: https://github.com/jenkinsci/jenkinsfile-runner.git | ||
credentialsId: user1 | ||
branches: | ||
- name: master | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
payload/src/main/java/io/jenkins/jenkinsfile/runner/SCMContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.jenkins.jenkinsfile.runner; | ||
|
||
import com.cloudbees.plugins.credentials.Credentials; | ||
import edu.umd.cs.findbugs.annotations.CheckForNull; | ||
import hudson.scm.SCM; | ||
import io.jenkins.plugins.casc.ConfigurationContext; | ||
import io.jenkins.plugins.casc.ConfiguratorException; | ||
import io.jenkins.plugins.casc.ConfiguratorRegistry; | ||
import io.jenkins.plugins.casc.model.Mapping; | ||
import io.jenkins.plugins.casc.yaml.YamlSource; | ||
import io.jenkins.plugins.casc.yaml.YamlUtils; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
|
||
public class SCMContainer { | ||
private final SCM scm; | ||
private final Credentials credential; | ||
|
||
@DataBoundConstructor | ||
public SCMContainer(SCM scm, Credentials credential) { | ||
this.scm = scm; | ||
this.credential = credential; | ||
} | ||
|
||
public SCM getSCM() { | ||
return scm; | ||
} | ||
|
||
@CheckForNull | ||
public Credentials getCredential() { | ||
return credential; | ||
} | ||
|
||
public static SCMContainer loadFromYAML(File input) throws ConfiguratorException { | ||
ConfiguratorRegistry registry = ConfiguratorRegistry.get(); | ||
ConfigurationContext context = new ConfigurationContext(registry); | ||
|
||
YamlSource<Path> ys = YamlSource.of(input.toPath()); | ||
|
||
Mapping config = YamlUtils.loadFrom(Collections.singletonList(ys), context); | ||
|
||
return (SCMContainer) registry.lookupOrFail(SCMContainer.class).configure(config, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
demo | ||
tests/jenkinsfile-runner-test-framework | ||
**/.git* | ||
tests/.jenkinsfile-runner-test-framework | ||
**/.git* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.