NewETAPE projectEmuframe Tape Server (ETAPE) project
COBOL for Linux
This page was auto-translated from Spanish

IBM Bob in the pipeline: fix COBOL automatically

In IBM Bob with COBOL and Podman on RHEL I asked Bob, from the chat, to fix a COBOL program until it passed the test of the container from IBM COBOL for Linux on x86 in a container: compile and test with Podman.

In this article I do it without the chat: a script runs the pipeline and, if the test fails, calls Bob Shell in non-interactive mode (bob run) to fix the program. Then it runs the pipeline again to check the result.

This is a lab idea: a way to try, in isolation, something that occurred to me. There are probably better or more complete ways to do it. The idea is to see that it works and that everyone adapts it to what they need, always taking into account what the IBM licenses allow.

With bob run, Bob does not ask for permission: according to the IBM documentation, all tools are approved in advance, so it can change files and run commands without asking. IBM recommends limiting what it can spend and do (--max-cost, --max-turns) and not using it in production.

IBM documentation: Starting a non-interactive session

Create an API key

In non-interactive mode, Bob Shell does not use the IBMid sign-in: it needs an API key in the BOB_API_KEY variable. The key has no extra cost: it is tied to the subscription and what you spend with it comes from the same Bobcoins. According to the IBM documentation, keys are also available in the trial.

https://bob.ibm.com/admin/apikeys

I create it in the Bob portal, in API keys, with the Create button. The key type is Inference.

IBM Bob in the pipeline: fix COBOL automatically – screenshot 1

We fill in the data.

To avoid surprises in the future (the key leaking by some mistake), I recommend setting an expiration date.

IBM Bob in the pipeline: fix COBOL automatically – screenshot 2

We copy or download it.

It is important to keep the API key in a safe place

IBM Bob in the pipeline: fix COBOL automatically – screenshot 3

The key is only shown once, when you create it. I save it on the virtual machine in a file that only I can read:

nano ~/.bob-api-key
chmod 600 ~/.bob-api-key
ls -l ~/.bob-api-key

In nano I paste only the key, nothing else, and save. The script reads it from that file, so the key does not appear in the script.

IBM Bob in the pipeline: fix COBOL automatically – screenshot 4

IBM Bob in the pipeline: fix COBOL automatically – screenshot 5

Before setting up the script, I check that Bob works without a UI with the key. Plain bob opens the interactive UI; the mode without a UI is bob run:

cd ~/cobol-bob
export BOB_API_KEY="$(cat ~/.bob-api-key)"
bob run --format json "Reply only with the word OK" < /dev/null
echo $?

IBM Bob in the pipeline: fix COBOL automatically – screenshot 6

Bob returns a JSON with "status":"success", what it cost ("session_costs": 0.02188 Bobcoins) and its answer ("last_message":"OK"), and the return code is 0. The < /dev/null is there so that Bob does not wait for data on standard input.

Prepare the folder

I use the same folder as in the other article (IBM Bob with COBOL and Podman on RHEL), ~/cobol-bob, with the cobol-linux container, the pipeline.sh, the expected result (expected.txt) and the copy of the program with errors (invoice-buggy.cbl). I put the program back with the errors and delete what the previous tests generated:

cd ~/cobol-bob
cp invoice-buggy.cbl src/invoice.cbl
rm -f src/invoice src/invoice.lst src/output.txt

IBM Bob in the pipeline: fix COBOL automatically – screenshot 7

The instructions for Bob

The instructions go in a file, ~/cobol-bob/prompt.txt. They are similar to the ones in the other article, but now Bob also receives the output of the pipeline that failed:

The pipeline that compiles and tests src/invoice.cbl failed. Its output is below.

Return codes: 1 = compilation error, 2 = the output does not match src/expected.txt, 3 = the program ended with a return code other than 0. The compilation listing is in src/invoice.lst.

Fix src/invoice.cbl so that the pipeline passes. Rules:
- Do not change src/expected.txt or src/pipeline.sh: the expected result is correct.
- Keep the COBOL fixed format (sequence numbers in columns 1-6, area A from column 8 and area B from column 12).
- You can run the pipeline to check your fix: podman run --rm -v ./src:/src:Z cobol-linux
- At the end, list the errors you fixed.

IBM Bob in the pipeline: fix COBOL automatically – screenshot 8

IBM Bob in the pipeline: fix COBOL automatically – screenshot 9

The script

The ~/cobol-bob/ci.sh script does what a continuous integration system would do: it runs the pipeline and, if it fails, it passes the output and the instructions to Bob, and tries again. It tries at most three times, so that it does not get stuck in a loop spending Bobcoins.

#!/bin/bash
# CI: run the pipeline; if it fails, ask Bob to fix invoice.cbl and try again

cd ~/cobol-bob || exit 1
export BOB_API_KEY="$(cat ~/.bob-api-key)"

MAX_TRIES=3
for TRY in $(seq 1 $MAX_TRIES); do
    echo "=== Try $TRY: pipeline ==="
    podman run --rm -v ./src:/src:Z cobol-linux > pipeline.log 2>&1
    RC=$?
    cat pipeline.log
    if [ $RC -eq 0 ]; then
        echo "PIPELINE OK"
        exit 0
    fi

    echo "=== Pipeline failed (return code $RC): asking Bob ==="
    cat pipeline.log | bob run --max-cost 1 --max-turns 30 --format json "$(cat prompt.txt)" > bob-$TRY.json
    echo "Bob ended with return code $?"
done

echo "PIPELINE FAILED after $MAX_TRIES tries"
exit 1
  • The key is read from the file, so it does not appear in the script.
  • The pipeline output is passed to Bob on standard input, and the instructions as an argument.
  • --max-cost limits the Bobcoins each call to Bob can spend and --max-turns the number of steps.
  • --format json leaves Bob's result in a JSON file (bob-1.json, bob-2.json…).
  • The script does not trust Bob: after each fix it runs the pipeline again, and it only ends successfully if the test passes.
chmod +x ~/cobol-bob/ci.sh

IBM Bob in the pipeline: fix COBOL automatically – screenshot 10

IBM Bob in the pipeline: fix COBOL automatically – screenshot 11

Run the script

cd ~/cobol-bob
./ci.sh
echo $?

On the first try, the pipeline fails in the compilation with the error IGYPS2121-S ("WS-TOTAL-VAR" was not defined as a data-name) and return code 1, so the script calls Bob. While Bob works nothing shows on screen, because its output goes to the bob-1.json file; only the Node.js SQLite warning appears. Bob ends with return code 0.

On the second try, the program compiles without warnings, shows the correct amounts and the test passes. The script ends with PIPELINE OK and return code 0. Bob was only needed once.

IBM Bob in the pipeline: fix COBOL automatically – screenshot 12

The result

Bob's result is in bob-1.json:

cat ~/cobol-bob/bob-1.json

IBM Bob in the pipeline: fix COBOL automatically – screenshot 13

  • "status":"success": Bob ended successfully.
  • "duration_ms":15108: it took about 15 seconds.
  • "session_costs": it spent 0.183 Bobcoins, below the limit I set ("max_cost":1).
  • "tool_calls":6: it used its tools 6 times (for example, to read and change invoice.cbl).
  • "last_message": its explanation of the two errors it fixed, WS-TOTAL-VAR to WS-TOTAL-VAT and UNTIL WS-I = 3 to UNTIL WS-I > 3, as in the other article.
© 2026 Emuframe·🍪 This site only uses functional cookies. No tracking or personal data collection.

On this page