首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在GitLab中自动下载资源

在GitLab中自动下载资源
EN

Stack Overflow用户
提问于 2021-02-13 03:15:39
回答 1查看 82关注 0票数 0

我正在构建一个应用程序,它依赖于静态资源文件。我希望能够找到一种方法,在工作流程中的特定时间下载资源文件。

我已经看到了git-hooks,我也看到了GitLab运行者等等。我没有偏好,我只是想能够简单地创建下载资源文件的自动化。

EN

回答 1

Stack Overflow用户

发布于 2021-02-17 06:47:12

我的GitLab.cli最终看起来如下所示:

我只需要生成一个新的私钥和公钥来添加到repo和一些命令中,这些命令是我从代码注释中可以找到的一堆不同的资源中收集的。

代码语言:javascript
复制
#resources that I used
#https://forum.gitlab.com/t/is-it-possible-to-commit-artifacts-into-the-git/22218/7
#https://forum.gitlab.com/t/git-push-from-inside-a-gitlab-runner/30554/5
#https://marcosschroh.github.io/posts/autobumping-with-gitlab/
#https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
#https://docs.gitlab.com/ee/ci/ssh_keys/
#https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys
#https://forum.gitlab.com/t/how-to-skip-the-pipeline-from-job-gitlab/44947/2
#https://docs.gitlab.com/ee/ci/yaml/#skip-pipeline

build-job:
  stage: build
  before_script:
    ##
    ## Create the SSH directory and give it the right permissions
    ##
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh

    ##
    ## Install ssh-agent if not already installed, it is required by Docker.
    ## (change apt-get to yum if you use an RPM-based image)
    ##
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'


    # - ssh-keyscan $GITLAB_URL >> ~/.ssh/known_hosts
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts

    ##
    ## Run ssh-agent (inside the build environment)
    ##
    - eval $(ssh-agent -s)

    ##
    ## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
    ## We're using tr to fix line endings which makes ed25519 keys work
    ## without extra base64 encoding.
    ## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
    ##
    # - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    # - echo "$SSH_PRIVATE_KEY" | ssh-add - > /dev/null


    - git config --global user.name "$CI_USERNAME"
    - git config --global user.email "$CI_EMAIL"
    - echo "$SSH_PUBLIC_KEY" >> ~/.ssh/id_rsa.pub
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

  script:
    # test out stuff from 
    # https://gitlab.com/gitlab-org/gitlab-foss/-/issues/18106#note_12209180

    - echo "Hello, $GITLAB_USER_LOGIN!"
    # for your information
    - whoami
    - printenv

    - git config --global user.name "${CI_USERNAME}"
    - git config --global user.email "${CI_EMAIL}"
    - git remote -v
    - git status
    # make your changes
    - touch test.txt
    - git add . 
    - git status
    - git remote -v
    # - git checkout master
    # - git merge ci_processing
    - git commit -m "Compiled PDF from $CI_COMMIT_SHORT_SHA [skip ci]" || echo "No changes, nothing to commit!"
    - git remote rm origin && git remote add origin git@gitlab.com:$CI_PROJECT_PATH.git
    - git push origin HEAD:$CI_COMMIT_REF_NAME # Pushes to the same branch as the trigger
    # push changes
    # always return true so that the build does not fail if there are no changes
    # - git push origin ci_processing:${CI_BUILD_REF_NAME} || true
    # - git push origin ci_processing:${CI_COMMIT_REF_NAME}
    # - git push origin ci_processing

# test-job1:
#   stage: test
#   script:
#     - echo "This job tests something"

# test-job2:
#   stage: test
#   script:
#     - echo "This job tests something, but takes more time than test-job1."
#     - echo "After the echo commands complete, it runs the sleep command for 20 seconds"
#     - echo "which simulates a test that runs 20 seconds longer than test-job1"
#     - sleep 20

# deploy-prod:
#   stage: deploy
#   script:
#     - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66177778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档