2022-08-10 16:38:31 -07:00
# Configure Valet to work with Jenkins
In this lab, you will use the Valet `configure` command to set up the required information to communicate with the Jenkins and GitHub instances. The `configure` command can be used for all of the supported providers, in this lab we will be focusing on Jenkins.
- [Prerequisites ](#prerequisites )
- [Configuring Valet ](#configuring-valet )
- [Verify Valet Works ](#verify-valet-works )
- [Next Lab ](#next-lab )
## Prerequisites
2022-08-25 16:57:10 -07:00
1. Followed [steps ](../jenkins/readme.md#valet-labs-for-jenkins ) to set up your codespace environment and start your Jenkins instance.
2022-08-10 16:38:31 -07:00
## Configuring Valet
1. Login to the Jenkins instance to generate a personal access token:
1. Click the `PORTS` tab in the codespace terminal window.
2. In the `PORTS` tab find the row for port 8080.
3. Hover over the address under the `Local Address` column, and click the globe to "open in browser".
4. Login to the Jenkins server and generate a Jenkins API token.
- Click the `admin` button located within the top right menu.
- Click on the `configure` gear located on the left hand panel.
- Under the `API token` section, click `Add new Token` .
2022-08-25 16:57:10 -07:00
- Add a default name to your token, then click `Generate` .
2022-08-10 16:38:31 -07:00
- Copy the token that was generated and record token for a later step.
2022-08-11 15:53:36 -07:00
2022-08-25 16:28:07 -07:00

2022-08-11 15:53:36 -07:00
2022-08-10 16:38:31 -07:00
2. Create a GitHub personal access token (PAT).
- Navigate to your GitHub `Settings` - click your profile photo and then click `Settings` .
- Go to `Developer Settings`
- Go to `Personal Access Tokens` -> `Legacy tokens (if present)`
- Click `Generate new token` -> `Legacy tokens (if present)` . If required, provide your password.
- Select at least these scopes: `read packages` and `workflow` . Optionally, provide a text in the **Note** field and change the expiration.
- Click `Generate token`
- Copy the token somewhere safe and temporary.
3. Run Valet configure commands
- In the codespace terminal window click back to the `TERMINAL` tab.
2022-08-25 16:57:10 -07:00
- Within the terminal, ensure you are in the root directory.
2022-08-11 15:48:51 -07:00
- Run `gh valet configure` .
2022-08-10 16:38:31 -07:00
- Use the down arrow key to highlight `Jenkins` , press the spacebar to select, then hit enter to accept.
- At the prompt enter your GitHub Username and press enter.
2022-08-18 09:12:54 -04:00
- At the GitHub Container Registry prompt enter the GitHub PAT generated in step 2 and press enter
- At the GitHub PAT prompt enter the GitHub PAT generated in step 2 and press enter.
2022-08-10 16:38:31 -07:00
- At the GitHub url prompt enter the GitHub instance url or hit enter to accept the default, if you are using github.com then the default is the right choice.
2022-08-18 09:12:54 -04:00
- At the Jenkins token prompt enter the Jenkins access token from step 1 and press enter.
2022-08-10 16:38:31 -07:00
- At the Jenkins url prompt enter `http://localhost:8080/` and press enter.
2022-08-25 16:57:10 -07:00
- At the Personal access token to fetch source code in GitHub prompt, if any of your Jenkins pipelines have source code in a GitHub repository enter the GitHub PAT that would have access to these files.
2022-08-10 16:38:31 -07:00
4. If all went well you should see a similar output in your terminal:
2022-08-25 16:28:07 -07:00

2022-08-10 16:38:31 -07:00
## Verify Valet Works
To verify Valet works we are going to run a `update` and `dry-run` command. We will go further into details about the `dry-run` command in a later lab, but for now we want to get the latest version of Valet and confirm that Valet can perform a dry-run with no errors.
1. In the codespace terminal update Valet by running `gh valet update`
2. In the terminal you should see a confirmation that it logged into the GitHub Container Registry and pulled the latest version.
2022-08-25 16:28:07 -07:00
```
Login Succeeded
latest: Pulling from valet-customers/valet-cli
Digest: sha256:a7d00dee8a37e25da59daeed44b1543f476b00fa2c41c47f48deeaf34a215bbb
Status: Image is up to date for ghcr.io/valet-customers/valet-cli:latest
ghcr.io/valet-customers/valet-cli:latest
` ``
2022-08-10 16:38:31 -07:00
2022-08-25 16:28:07 -07:00
3. Next, lets run the dry-run command in the codespaces terminal, to verify we can talk to Jenkins
2022-08-10 16:38:31 -07:00
` ``
gh valet dry-run jenkins --source-url https://localhost:8080/job/test_pipeline/ --output-dir ./tmp/dry-run-lab
` ``
2022-08-25 16:28:07 -07:00
4. In the terminal you should see the command was successful, if not it is a good time to practice the configure command again and make sure the access tokens values are correct and were generated with the correct permissions.
2022-08-11 15:53:36 -07:00

2022-08-10 16:38:31 -07:00
### Next Lab
2022-08-25 16:28:07 -07:00
[Audit Jenkins using the Valet audit command ](valet-audit-lab.md#audit-jenkins-pipelines-using-the-valet-audit-command )