# Jenkins Integration

### Introduction <a href="#introduction" id="introduction"></a>

`Jenkins` is an open source automation server that helps you to automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.

{% hint style="info" %}
The following configuration examples show how to install & run the scanner using an API Token stored as a secret named `XYGENI_TOKEN`. See [Generate Xygeni API Token for Scanner](https://docs.xygeni.io/xygeni-administration/profile#generate_token_for_scanner-1) or ask your Xygeni administrator to generate it.

It is recommended to store the token as a [Jenkins Credential](https://www.jenkins.io/doc/book/using/using-credentials/#using-credentials) of type "Secret text".
{% endhint %}

### Using the xygeni-scanner.zip <a href="#using_the_installation_script" id="using_the_installation_script"></a>

Replace \<PROJECT\_NAME> for the name of the project that you want to create in Xygeni.

```linenums
pipeline {
  agent any
  environment {
    XYGENI_TOKEN = credentials('XYGENI_TOKEN')
  }
  stages {
    stage('Install Xygeni scanner') {
      steps {
        sh '''
          curl -s -L "https://get.xygeni.io/latest/scanner/xygeni-release.zip" -o xygeni_scanner.zip
          unzip -qq xygeni_scanner.zip -d "${WORKSPACE}"
          rm xygeni_scanner.zip
        '''
      }
    }
    stage('Scan for issues') {
      steps {
        sh '''
          set -x # Activate debug mode to print commands inside the script
          $WORKSPACE/scanner/xygeni scan \
          -n <PROJECT_NAME> \
          --dir ${WORKSPACE}
        '''
      }
    }
  }
}
```

### Using the docker image <a href="#using_the_docker_image" id="using_the_docker_image"></a>

If it is not possible to install the scanner in the Jenkins host running the pipeline, you may run the docker image instead.

Replace \<PROJECT\_NAME> for the name of the project that you want to create in Xygeni.

```linenums
pipeline {
  agent any
  environment {
    XYGENI_TOKEN = credentials('XYGENI_TOKEN')
  }
  stages {
    stage('Scan for issues') {
      steps {
        sh '''
        docker run \
          -v ${WORKSPACE}:/app
          -v $DD_CONF:/opt/xygeni_scanner/conf \
          -t -rm \
          xygeni_scanner/xygeni scan \
          -n <PROJECT_NAME> --dir /app
        '''
      }
    }
  }
}
```

{% hint style="info" %}
See [Xygeni Scanner docker image](https://docs.xygeni.io/xygeni-scanner-cli/xygeni-cli-overview/xygeni-cli-docker-image) for more details.
{% endhint %}
