FlowCI / flow-core-x

Powerful and user-friendly CI/CD server with high availability, parallel processing, runner auto-scaling
https://flowci.github.io
Apache License 2.0
1.61k stars 121 forks source link

java.lang.Exception: No such property: FLOWCI_GIT_BRANCH for class: Script1 #392

Closed genkin-he closed 3 years ago

genkin-he commented 3 years ago

我想只是master分支才触发构建,写了个condition运行的时候报错了,不知道我的用法是不是有问题。

java.lang.Exception: No such property: FLOWCI_GIT_BRANCH for class: Script1

- name: build
    envs:
    condition: |
      return "${FLOWCI_GIT_BRANCH}" == "master"

image

gy2006 commented 3 years ago

这个错误一般是因为没有 FLOWCI_GIT_BRANCH 这个环境变量,任务是手动创建的还是 GIT 触发创建的? 目前的版本是什么?这个错误在最新版本应该是修复了,手动创建的任务 condition是不会执行的,如果有 flow.ci 的 image 的话 server.sh 启动不会 pull 最新的镜像 :( .. 可以从新 pull 下

genkin-he commented 3 years ago

我刚刚拉了最新版本的core,似乎还是不行。处理不了pull request 的情况。 image

gy2006 commented 3 years ago

感谢反馈,这里有个 bug, PR 的时候 FLOWCI_GIT_BRANCH 这个变量是没有的, 在执行 conditon 的时候会报错,刚刚已经修复了,可以 pull 下最新镜像。

环境变量在 push/tag 和 pr 的时候会有所不同,可以参考一下文档。

https://github.com/FlowCI/docs/blob/master/cn/agents/vars.md

Commit

FLOWCI_GIT_BRANCH
FLOWCI_GIT_AUTHOR
FLOWCI_GIT_COMMIT_ID
FLOWCI_GIT_COMMIT_MESSAGE
FLOWCI_GIT_COMMIT_TIME
FLOWCI_GIT_COMMIT_URL
FLOWCI_GIT_COMMIT_NUM

PR

FLOWCI_GIT_PR_TITLE
FLOWCI_GIT_PR_MESSAGE
FLOWCI_GIT_PR_URL
FLOWCI_GIT_PR_TIME
FLOWCI_GIT_PR_NUMBER

FLOWCI_GIT_PR_HEAD_REPO_NAME
FLOWCI_GIT_PR_HEAD_REPO_BRANCH
FLOWCI_GIT_PR_HEAD_REPO_COMMIT

FLOWCI_GIT_PR_BASE_REPO_NAME
FLOWCI_GIT_PR_BASE_REPO_BRANCH
FLOWCI_GIT_PR_BASE_REPO_COMMIT

如果只是要 master 触发的话可以参考一下 (Github PR_MERGE 之后会有个 PUSH 的操作,第二个 if 可以不用)

envs:
  # Git config
  FLOWCI_GIT_URL: "https://github.com/FlowCI/gin.git"

condition: |
  if ("${FLOWCI_GIT_EVENT}" == "PUSH" || "${FLOWCI_GIT_EVENT}" == "TAG") {
      return "${FLOWCI_GIT_BRANCH}" == "master" 
  }

  if ("${FLOWCI_GIT_EVENT}" == "PR_MERGED") {
    return "${FLOWCI_GIT_PR_BASE_REPO_BRANCH}" == "master"  
  }

  return false
genkin-he commented 3 years ago

感谢!