Check challenges
This guide shows you how to use lifecycle scripts in your challenges.
Earlier in the Getting Started guide we created a sample track which includes two lifecycle scripts.
Look inside the 01-creating-a-directory folder and you'll see the check-container and solve-container scripts.

Check Scripts

Check scripts run when the learner clicks on the Check button at the bottom of the assignment panel. The check script is meant to verify that the learner has correctly completed the challenge task. Here's the check-container script that was created for the first challenge. It checks to see whether a directory called instruqt was created.
1
#!/bin/bash
2
set -euxo pipefail
3
4
echo "Checking if the folder instruqt exists."
5
6
if [ -d /root/instruqt ]
7
then
8
echo "The folder instruqt exists"
9
else
10
fail-message "There is no folder named instruqt, did you create it?"
11
fi
Copied!
Our docs contain several examples of things you can test for in check scripts.

Solve Scripts

Solve scripts run when users click the Skip button (if enabled) and also when you run instruqt track test. The solve script is meant to simulate a human user solving the challenge. In our example above the user needs to create a directory. Here's how the solve script looks:
1
#!/bin/bash
2
set -euxo pipefail
3
4
echo "Creating folder instruqt"
5
6
mkdir -p /root/instruqt;
Copied!
Solve scripts can be used to solve complex technical challenges involving external systems or API calls. Your challenge as a developer is to figure out how to complete the same steps a human user would do with code.

Create check and solve scripts

In your Getting Started track go into the 02-second-challenge directory and edit the check-container file. Let's add a check to ensure that the cowsay package is installed. Replace all of the content in the file with this example code:
1
#!/bin/bash
2
set -euxo pipefail
3
4
echo "Checking whether cowsay is installed..."
5
6
dpkg -l | grep cowsay || fail-message "Oops, it looks like cowsay is not installed."
Copied!
Note how we've made use of the bash boolean OR operator: ||. The code translates to "list all packages and if cowsay is not found, send the failure message.
Next, edit the solve-container script and add the solution. Replace all the content in the file with this example code:
1
#!/bin/bash
2
set -euxo pipefail
3
4
echo "Installing cowsay..."
5
6
apt -y update
7
apt -y install cowsay
Copied!
Save your changes and start up your track. Proceed to the second challenge and try the Check button. You should see the error message. You can either solve the challenge manually by running apt -y install cowsay or by clicking the Skip button to have the solve script do it for you.
Last modified 15d ago