ERROR: Job failed: exit status 1

I have this configuration in my .gitlab-ci.yml:

stages:
  - build
  - test
  - deploy

compile_magento:
  stage: build
  script:
    - chmod -Rf 777 pub/ var/ generated/
    - php bin/magento setup:di:compile

pull_from_remote:
  stage: test
  script:
    - cd /home/rafael/Desktop/magento
    - git checkout -f
    - git clean -fd
    - git pull
    - php bin/magento setup:di:compile
    - php bin/magento indexer:reindex
    - php bin/magento setup:static-content:deploy -f
    - chmod -Rf 777 pub/ var/ generated/

remove_folder:
  stage: deploy
  script:
    - cd /home/rafael/Desktop/magentodev
    - chmod -Rf 777 pub/ var/ generated/
    - php bin/magento cache:clean
    - php bin/magento cache:flush
    - chmod -Rf 777 pub/ var/ generated/
    - cd /home/rafael/Desktop/magento
    - php bin/magento cache:clean
    - php bin/magento cache:flush
    - chmod -Rf 777 pub/ var/ generated/

And I get the error ERROR: Job failed: exit status 1 at the end of the job pull_from_remote:

Running with gitlab-runner 13.9.0 (2ebc4dc4)
  on gitlab magento -qMypuLw
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on pcfixorafael...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/-qMypuLw/0/rafaelmoreiraskrey/magento-dev/.git/
Checking out 2b5a8b39 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ cd /home/rafael/Desktop/magento
$ git checkout -f
Your branch is up to date with 'origin/master'.
$ git clean -fd
$ git pull
Already up to date.
$ php bin/magento setup:di:compile
Compilation was started.
%message% 0/9 [>---------------------------]   0% < 1 sec 103.0 MiBProxies code generation... 0/9 [>-----------------------]   0% < 1 sec 103.0 MiB
Proxies code generation... 1/9 [==>---------------------]  11% < 1 sec 107.0 MiB
Repositories code generation... 1/9 [==>----------------]  11% < 1 sec 107.0 MiB
Repositories code generation... 2/9 [====>--------------]  22% 4 secs 242.0 MiB
Service data attributes generation... 2/9 [===>----------]  22% 4 secs 242.0 MiB
Application code generator... 3/9 [====>---------]  33% 4 secs 242.0 MiB
Application code generator... 4/9 [======>-------]  44% 8 secs 264.0 MiB
Interceptors generation... 4/9 [======>-------]  44% 8 secs 264.0 MiB
Interceptors generation... 5/9 [=======>------]  55% 18 secs 308.0 MiB
Area configuration aggregation... 5/9 [=======>------]  55% 18 secs 308.0 MiB
Area configuration aggregation... 6/9 [=========>----]  66% 21 secs 414.0 MiB
Interception cache generation... 6/9 [=========>----]  66% 21 secs 414.0 MiB
Interception cache generation... 7/9 [==========>---]  77% 24 secs 412.0 MiB
App action list generation... 7/9 [==========>---]  77% 24 secs 412.0 MiB
Plugin list generation... 8/9 [============>-]  88% 24 secs 412.0 MiB
Plugin list generation... 9/9 [==============] 100% 25 secs 412.0 MiB
Generated code and dependency injection configuration successfully.
$ php bin/magento indexer:reindex
Design Config Grid index has been rebuilt successfully in 00:00:00
Customer Grid index has been rebuilt successfully in 00:00:00
Category Products index has been rebuilt successfully in 00:00:01
Product Categories index has been rebuilt successfully in 00:00:00
Catalog Rule Product index has been rebuilt successfully in 00:00:00
Product EAV index has been rebuilt successfully in 00:00:00
Stock index has been rebuilt successfully in 00:00:00
Inventory index has been rebuilt successfully in 00:00:00
Catalog Product Rule index has been rebuilt successfully in 00:00:00
Product Price index has been rebuilt successfully in 00:00:00
Catalog Search index has been rebuilt successfully in 00:00:00
$ php bin/magento setup:static-content:deploy -f
Deploy using quick strategy
frontend/Magento/blank/en_US            0/2497              >--------------------------- 0%     < 1 sec
frontend/Magento/blank/en_US            1528/2497           =================>---------- 61%    1 sec
frontend/Magento/blank/en_US            2417/2497           ===========================> 96%    3 secs
frontend/Magento/blank/en_US            2497/2497           ============================ 100%   3 secs              
adminhtml/Magento/backend/en_US         1222/2556           =============>-------------- 47%    1 sec
frontend/Magento/blank/en_US            2497/2497           ============================ 100%   3 secs              
adminhtml/Magento/backend/en_US         2406/2556           ==========================>- 94%    3 secs
frontend/Magento/blank/en_US            2497/2497           ============================ 100%   3 secs              
adminhtml/Magento/backend/en_US         2407/2556           ==========================>- 94%    4 secs
frontend/Magento/blank/en_US            2497/2497           ============================ 100%   3 secs              
adminhtml/Magento/backend/en_US         2556/2556           ============================ 100%   4 secs              
frontend/Magento/luma/en_US             524/2513            =====>---------------------- 20%    1 sec
frontend/Magento/blank/en_US            2497/2497           ============================ 100%   3 secs              
adminhtml/Magento/backend/en_US         2556/2556           ============================ 100%   4 secs              
frontend/Magento/luma/en_US             2513/2513           ============================ 100%   1 sec
frontend/Magento/blank/en_US            2497/2497           ============================ 100%   3 secs              
adminhtml/Magento/backend/en_US         2556/2556           ============================ 100%   4 secs              
frontend/Magento/luma/en_US             2513/2513           ============================ 100%   1 sec
Execution time: 10.628154993057
$ chmod -Rf 777 pub/ var/ generated/
ERROR: Job failed: exit status 1

I already removed .bash_logout .bash_profile from /home/gitlab-runner.

Gitlab-runner version: arch=amd64 os=linux pid=78246 revision=2ebc4dc4 version=13.9.0

It looks like the chmod line has failed, is that right? Can you print the contents of those directories?

You can try to run the command manually after the Job fails to see the actual error from chmod.