Skip to content

Commit

Permalink
Merge pull request #18 from snow-actions/jcasc-plugins
Browse files Browse the repository at this point in the history
Add JCasC plugins
  • Loading branch information
SnowCait authored May 17, 2022
2 parents 2b6e37b + e831cad commit 2fc7b68
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
- run: |
crumb=$(curl -sS -c cookie $JENKINS_URL/crumbIssuer/api/json)
echo "CRUMB_HEADER=$(echo $crumb | jq -r '.crumbRequestField'): $(echo $crumb | jq -r '.crumb')" >> $GITHUB_ENV
- run: test $(curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/api/json | jq '.jobs | length') -eq 0
- run: test $(curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/api/json | jq '.jobs | length') -eq 1

# Jenkins CLI
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ A few features are available.

## Usage

1. Copy `$JENKINS_HOME/jobs/*/config.xml` from existing Jenkins to `jenkins_home/` in a repository
1. You can put `jenkins_home/jenkins.yaml` if [Jenkins Configuration as Code](https://www.jenkins.io/projects/jcasc/) (optional)
1. Copy `$JENKINS_HOME/jobs/*/config.xml` from existing Jenkins to `jenkins_home/` in a repository
or you can put `jenkins_home/jenkins.yaml` if [Jenkins Configuration as Code (JCasC)](#jenkins-configuration-as-code-jcasc)
1. Create a workflow with the jenkins_home path

```yml
Expand Down Expand Up @@ -42,8 +42,21 @@ See [action.yml](action.yml)

## Examples

### Workflow

See [test.yml](.github/workflows/test.yml)

### Jenkins Configuration as Code (JCasC)

See [jenkins.yaml](test-resources/jenkins.yaml)

Documents
- https://www.jenkins.io/doc/book/managing/casc/
- https://www.jenkins.io/projects/jcasc/
- https://plugins.jenkins.io/configuration-as-code/
- https://plugins.jenkins.io/configuration-as-code-groovy/
- https://plugins.jenkins.io/job-dsl/

## Supported

### Runners
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ runs:
sudo chown -R 1000:1000 $JENKINS_HOME
shell: bash
if: env.JENKINS_HOME != ''
- name: Install JCasC plugin
- name: Install JCasC plugins
run: |
if [ -f "$JENKINS_HOME/jenkins.yaml" ]; then
echo 'configuration-as-code' >> $GITHUB_ACTION_PATH/plugins.txt
echo 'configuration-as-code-groovy' >> $GITHUB_ACTION_PATH/plugins.txt
echo 'job-dsl' >> $GITHUB_ACTION_PATH/plugins.txt
fi
shell: bash
- run: cat $GITHUB_ACTION_PATH/plugins.txt
Expand Down
20 changes: 20 additions & 0 deletions test-resources/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@ jenkins:
value: foo
- key: VARIABLE2
value: bar
groovy:
- script: >
println("This is Groovy script!");
jobs:
- script: |
pipelineJob('job-dsl-plugin') {
definition {
cpsScm {
scm {
git {
remote {
url('https://github.com/jenkinsci/job-dsl-plugin.git')
}
branch('*/master')
}
}
lightweight()
}
}
}

0 comments on commit 2fc7b68

Please sign in to comment.