Jenkins: a job to check a Github organization’s public repositories list
Tags: docker, jenkins, devops, security
Published: 2019-04-16 12:56:09

---
title: Jenkins: a job to check a Github organization’s public repositories list
published: true
tags: Docker,Jenkins,DevOps,security
canonical_url: https://rtfm.co.ua/en/jenkins-a-job-to-check-a-github-organizations-public-repositories-list/
---

![](https://rtfm.co.ua/wp-content/uploads/2016/01/Jenkins.sh-600x600-e1453134979914.png)Proceeding with a Github repositories checker.

To recall: the idea is to have such a check in case if somebody from developers accidentally will share our project’s private repository as public, or will create a public repository instead of making it as a private one – we will get a Slack alarm about such a new repository.

The tool to check and send Slack notification was written in the [Go: checking public repositories list in Github. Go slices comparison. The first Golang experience](https://rtfm.co.ua/en/go-checking-public-repositories-list-in-github-go-slices-comparison-the-first-golang-experience/ "Permalink to Go: checking public repositories list in Github. Go slices comparison. The first Golang experience.") post.

In this post – will create a Docker image and a Jenkin’s job which will be running each night to execute check.

### `Dockerfile`

Create a `Dockerfile`.

Use `golang:alpine` and:

1. copy the utility’s source file
2. install Go’s dependencies
3. build a binary to the `/go/bin` directory as `github-checker` executable file
4. add default action – run `/go/bin/github-checker`

The file:

```
# alpine as mininal image
FROM golang:alpine
# git for go get
RUN apk update && apk add --no-cache git
# copy source from a current dir
COPY go-github-public-repos-checker.go .
# install deps
RUN go get -d -v
# build to /go/bin
RUN go build -o /go/bin/github-checker
# set default entrypoint
CMD ["/go/bin/github-checker"]
```

Read more about `CMD` vs `ENTRYPOINT` [here>>>](http://goinbigdata.com/docker-run-vs-cmd-vs-entrypoint/).

Build an image:

```
$ docker build -t projectname/projectname-github-checker:1.0 .
```

Check it.

Set environment variables:

```
$ export GITHUB_ORG_NAME="rtfmorg"
$ export ALLOWED_REPOS="org-repo-1-pub org-repo-2-pub"
$ export SLACK_CHANNEL="#general"
$ export SLACK_URL="https://hooks.slack.com/services/T16***WRE"
```

Run container passing variables with the `-e`:

```
$ docker run -ti -e GITHUB_ORG_NAME=${GITHUB_ORG_NAME} -e ALLOWED_REPOS="${ALLOWED_REPOS}" -e SLACK_CHANNEL=${SLACK_CHANNEL} -e SLACK_URL=${SLACK_URL} projectname/projectname-github-checker:1.0
Checking org-repo-1-pub
OK: repo org-repo-1-pub found in Allowed
Checking org-repo-2-pub
OK: repo org-repo-2-pub found in Allowed
```

Push to the DockerHub:

```
$ docker push projectname/projectname-github-checker:1.0
```

### Jenkins

Create a new job and start Docker via _Pipeline script_:

[![](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_134704.png "Jenkins: проверка публичных репозиториев Github-организации")](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_134704.png)

The script itself:

```
node {
    stage('Check repositories') {
        docker.image('projectname/projectname-github-checker:1.0').run("-e GITHUB_ORG_NAME=${GITHUB_ORG_NAME} \
        -e ALLOWED_REPOS=${ALLOWED_REPOS} \
        -e SLACK_CHANNEL=${SLACK_CHANNEL} \
        -e SLACK_URL=${SLACK_URL}")
    }
}
```

Add parameters which will be passed to the container.

`SLACK_URL` contains token so set it as _Password Parameter_.

`ALLOWED_REPOS` contains a list to be parsed by Go in the utility, so set in the quotes:

![](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_132628.png "Jenkins: проверка публичных репозиториев Github-организации")

Add schedule, the [crontab.guru](https://crontab.guru/) can be used:

[![](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_124841.png "Jenkins: проверка публичных репозиториев Github-организации")](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_124841.png)

Run job, for testing – without one of our public repository in the `ALLOWED_REPOS` parameter:

[![](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_135007.png "Jenkins: проверка публичных репозиториев Github-организации")](https://rtfm.co.ua/wp-content/uploads/2019/04/Screenshot_20190416_135007.png)

Done.

### Similar posts

- <small>04/13/2019</small> [Go: checking public repositories list in Github. Go slices comparison. The first Golang experience.](https://dev.to/setevoy/go-checking-public-repositories-list-in-github-go-slices-comparison-the-first-golang-experience-1ddm)<small> (0)</small>
- <small>02/09/2017</small> [Azure: подключение дополнительного диска к VM и миграция Jenkins](https://rtfm.co.ua/azure-podklyuchenie-dopolnitelnogo-diska-k-vm-i-migraciya-jenkins/)<small> (0)</small>  
- <small>02/24/2017</small> [Jenkins: pipeline плагин и триггер билда через Github webhook](https://rtfm.co.ua/jenkins-pipeline-plagin-i-trigger-bilda-cherez-github-webhook/)<small> (1)</small>  
- <small>03/15/2019</small> [Jenkins: jenkins.model.RunIdMigrator doMigrate WARNING: found unexpected dir lastSuccessfulBuil](https://rtfm.co.ua/jenkins-jenkins-model-runidmigrator-domigrate-warning-found-unexpected-dir-lastsuccessfulbuil/)<small> (0)</small>